How to Open a PHP File
Open a PHP file in a text or code editor to read its source. To execute trusted PHP code, use a PHP interpreter or a configured PHP web server; double-clicking it in a browser does not run server-side PHP.
Choose what you need
Read or edit PHP source on Windows, Mac or Linux
Use VS Code or another plain-text code editor and choose File → Open. Notepad can display the source on Windows. Look for PHP tags such as <?php, which mark PHP code; HTML may appear in the same file.
Make edits in a copy or version-controlled project. Avoid rich-text editors that insert formatting, and keep the original filename and encoding unless the project requires a deliberate change.
Run a trusted command-line PHP script
With PHP installed, open a terminal in the project directory. Use php -v to confirm the interpreter is available, then php script.php for a trusted command-line script. A web application may also need dependencies, configuration, environment variables and a database.
Reading source is different from executing it. Do not run an unfamiliar script simply to find out what it contains.
Preview a local PHP webpage
For a trusted local project, PHP’s development server can serve the current directory with php -S 127.0.0.1:8000. Visit http://127.0.0.1:8000/ in your browser. This development server is for testing, not public production hosting; stop it when finished.
If a browser downloads PHP or shows source on a real website, server handling may be misconfigured. A local file URL does not create a PHP server. Renaming PHP to HTML removes execution rather than translating the application.
Frequently asked questions
Can Notepad open PHP?
Yes, for reading plain-text source. It does not execute the PHP program.
Why does my browser show PHP code?
The file may have been opened locally or the server may not be processing PHP. Use an appropriate interpreter or correctly configured server for trusted code.
Sources and further reading
Opening routes checked against the references below on October 11, 2026. Device menus, software support and protection policies can change.