File extensions

How to open a .php file

PHP source file · Source code

A .php file is source code, so any text editor opens it. If your browser downloaded one instead of showing a page, the server failed to execute it, which is a server problem rather than yours.

What a .php file actually is

PHP runs on the server. The visitor is supposed to receive the HTML it produces, never the code itself, which is why seeing a .php file at all is usually a symptom.

The file is plain text with code between <?php and ?> tags, readable in any editor without special software.

Why it will not open

Two very different situations. Either you are a developer wanting to read or edit it, which is trivial, or you visited a website and it downloaded a .php instead of loading, which means the server is misconfigured and not running PHP.

Renaming it to an extension you can open will not help: changing the extension does not convert the file, it only changes what Windows tries to open it with.

Step by step

Windows

  1. 01To read or edit: right-click, choose "Open with", then VS Code, Notepad++ or Notepad.
  2. 02To actually run it you need PHP installed plus a web server. XAMPP bundles both and is the usual route for local development.
  3. 03If a website downloaded the file at you, there is nothing to fix on your machine. The server is serving PHP as a download rather than executing it, and only its administrator can correct that.

macOS

  1. 01Open it in TextEdit with Format set to Plain Text, or in VS Code.
  2. 02In Terminal, "php -v" tells you whether PHP is available; recent macOS versions no longer bundle it.

What usually goes wrong

A downloaded .php can expose secrets

If a misconfigured server hands you the raw source, that source may contain database passwords and API keys. If it is your own site, treat those credentials as compromised and rotate them after fixing the configuration.

Programs that open .php

Our pick, in order. Every one links to the publisher's official download URL and the SHA-256 hash of the installer. Once you have downloaded it, you can check the file against our index before you run it.

If you end up downloading one of these from somewhere other than the publisher, what you can and cannot verify about that is worth two minutes.

Common questions

Why did a website download a .php file instead of opening it?
The server is not executing PHP and is serving the source as a download instead. That is a server misconfiguration. Nothing on your computer can fix it; the site administrator has to.
How do I run a PHP file on my computer?
You need PHP and a web server. XAMPP installs both together, after which you place the file in the htdocs folder and open it via localhost rather than double-clicking it.

Related formats