.php File Extension
.php file contains, how to open PHP source safely, how Poly supports it, and when to publish another format instead. File extension details for .php
Storage Only| File type | PHP source code |
|---|---|
| MIME type | |
| Encoding | Text, commonly UTF-8, with PHP code and optional embedded markup |
| Operating systems | Windows, macOS, Linux |
| Opens with | Visual Studio Code, PhpStorm, PHP CLI, Text editors |
| Poly support | Yes. Poly stores, syncs, shares, and versions PHP files. |
| Indexed by Poly | No. PHP source is currently searchable by filename only. |
| Preview in Poly | No. Download the file to inspect it in a code editor. |
| Poly agent | No. The Poly agent does not currently read PHP source. |
What kind of file is a .php?
A .php file is a text source file for PHP, a programming language widely used to create web applications and command-line tools. It can contain only PHP code or switch between PHP and ordinary HTML using <?php and ?> tags.1 There is no dependable magic number because valid PHP code need not begin at byte zero.
The commonly used application/x-httpd-php label is not registered by IANA as a media type.2 In Apache configurations it traditionally acts as a handler name, telling the server to process matching files with PHP. A browser normally receives the generated HTML, JSON, image, or other output, not the PHP source.
How do I open a .php on my computer?
Open PHP source in a text or code editor on Windows, macOS, or Linux. Visual Studio Code includes PHP syntax highlighting, bracket matching, completion, snippets, and linter integration.3 PhpStorm and other PHP-aware IDEs add project navigation, refactoring, and debugging tools.
Use the PHP command-line interface only when you intend to execute trusted code. The forms php script.php and php -f script.php both run a local script.4 A web browser cannot execute PHP itself. To test a web application, use a correctly configured local server or the project's documented development environment.
Poly support for .php
Poly stores, syncs, shares, and versions .php files, and makes them searchable by filename. It does not currently preview PHP source, index its contents, or make the code available to the Poly agent. Download the file and inspect it in a trusted editor. For agent analysis, provide a clearly labeled readable text copy together with any relevant configuration or companion files.
Poly never executes PHP code. That is especially important for uploaded scripts whose dependencies, environment variables, or intended server configuration are unknown.
History of .php
Rasmus Lerdorf created the first PHP tools in 1994 and released their source in June 1995. The project began as CGI tools and grew into a language for dynamic web applications.5 The .php suffix became the ordinary convention as PHP developed, while older deployments also used names such as .php3, .php4, .php5, and .phtml.
Apache's PHP installation guide still demonstrates an end-anchored .php rule. The anchor matters because a loose match could execute a misleading name such as upload.php.jpg.6
Working with .php and alternatives
Choose an output based on what you need:
| Goal | Best approach |
|---|---|
| Keep editable server-side logic | Retain .php and its project dependencies |
| Publish a static snapshot | Run trusted code in a controlled environment and save its output as .html |
| Share code with a text-only system | Make a clearly labeled plain-text copy |
| Move to another language | Rewrite and test the behavior |
Renaming a file does not convert or neutralize it. Changing index.php to index.html leaves the PHP statements untouched, while changing a server rule can make the same bytes executable. Before deployment, keep secrets outside the web root, review dependencies, and confirm that a request returns generated output rather than source code.
Footnotes
- PHP Project. PHP Tags. ↩
- Internet Assigned Numbers Authority. Media Types Registry. The application registry does not include
application/x-httpd-php. ↩ - Microsoft. PHP in Visual Studio Code. ↩
- PHP Project. Executing PHP Files from the Command Line. ↩
- PHP Project. History of PHP. ↩
- PHP Project. Apache 2.x on Unix Systems. ↩