.php File Extension

Learn what a .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 typePHP source code
MIME type
EncodingText, commonly UTF-8, with PHP code and optional embedded markup
Operating systemsWindows, macOS, Linux
Opens withVisual Studio Code, PhpStorm, PHP CLI, Text editors
Poly supportYes. Poly stores, syncs, shares, and versions PHP files.
Indexed by PolyNo. PHP source is currently searchable by filename only.
Preview in PolyNo. Download the file to inspect it in a code editor.
Poly agentNo. 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.

Do not double-click or run an unfamiliar PHP file merely to see what it does. Source code can read files, contact networks, and use any credentials available to its process.

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:

GoalBest approach
Keep editable server-side logicRetain .php and its project dependencies
Publish a static snapshotRun trusted code in a controlled environment and save its output as .html
Share code with a text-only systemMake a clearly labeled plain-text copy
Move to another languageRewrite 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

  1. PHP Project. PHP Tags.
  2. Internet Assigned Numbers Authority. Media Types Registry. The application registry does not include application/x-httpd-php.
  3. Microsoft. PHP in Visual Studio Code.
  4. PHP Project. Executing PHP Files from the Command Line.
  5. PHP Project. History of PHP.
  6. PHP Project. Apache 2.x on Unix Systems.
© Poly Corp. 2026