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.
What opens 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.
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
Open a .php file step by step
- Confirm the file really is a .php. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with VS Code or PhpStorm.
- On Mac, use VS Code or PhpStorm.
- On Linux, try VS Code or vim.
- Still stuck? Search for a dedicated PHP viewer rather than a generic one.
Why can't I open my .php file?
Almost always because no installed app understands PHP. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .php at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
PHP has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.
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. How sources are ranked and what is deliberately left out is set out in the methodology.