What is a .php file?
PHP Source File · Code and data · Rasmus Lerdorf / The PHP Group · 1995
A .php file is PHP source code, a language built for the web that runs on the server to generate pages. It powers a large share of the web, including WordPress, and mixes code with HTML.
What is a .php file used for?
PHP code lives between <?php and ?> tags and can be embedded directly in HTML. When a web server receives a request for a .php file, it runs the code and sends the resulting HTML to the browser, so visitors never see the source.
It is the language behind WordPress, Drupal and much of the web's back end. The files are plain text and open in any editor; running them normally means placing them under a PHP-capable web server.
How to open a .php file
The .php format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .php file.
Windows
- VS Code
- PhpStorm
- any text editor
macOS
- VS Code
- PhpStorm
- any text editor
Linux
- VS Code
- vim
- any text editor
Web
- Runs on a PHP-enabled web server
.php file signature (magic bytes)
Programs recognise a .php file by the bytes at the start of the file, not by its name. These are the signatures for PHP.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .php file?
A .php file is PHP source code, a language built for the web that runs on the server to generate pages. It powers a large share of the web, including WordPress, and mixes code with HTML.
How do I run a .php file?
Place it under a PHP-enabled web server, or run php file.php from a terminal with PHP installed for command-line scripts.
Why does my .php file show as text in the browser?
The server is not processing PHP. Opening the file directly, or a misconfigured server, sends the raw source instead of running it.
How do I open a .php file to edit it?
Any text editor works. VS Code or PhpStorm add highlighting, and can run and debug PHP projects.
Related formats
Sources
Details on this page were checked against authoritative references: