.php

How to Open PHP File: View, Edit, Run or Fix a .php Download

How you open a PHP file depends on what it really is. If a website gave you "download.php" instead of a PDF or photo, it's that document with the wrong name: rename it (the checker below tells you the right extension). If it's real PHP code, open PHP files in any text editor such as Notepad or VS Code, and run them with PHP itself, since browsers can't execute PHP.

Category: Web script / source code Language: PHP (The PHP Group) Format: Plain text Runs on: a web server with PHP

Choose what you need

Open PHP File Online: See What It Is & Read the Code (Free)

Drop a .php file below. The checker reads its first bytes to tell you whether it's really a PDF, Word file, image, video or web page with the wrong name, and gives it back with the correct extension. For real PHP code it shows a colored, read-only view, the PHP version it needs, and warning signs often found in hacked websites.

Good to know: nothing is executed. The checker never runs PHP; it only reads the file as data. Its security checks are pattern hints, not an antivirus scan.

🔒 Nothing is uploaded — your file never leaves this device

What is a PHP file?

A PHP file is a plain-text script written in PHP, a programming language that runs on web servers to build web pages. When you visit a page such as index.php, the server runs the code and sends your browser only the result: HTML, a PDF, an image or other data. You never see the PHP itself. PHP powers WordPress and countless other sites and web apps.

Because the file is just text, any text editor can open it. But a browser can't run it: you need the PHP program, usually as part of a web server. That's also why .php files sometimes end up in your Downloads folder by mistake, as the next diagram shows.

Why a download can end up named .php Your browser requests download.php. The server runs the PHP code and sends back a PDF. If the server doesn't send a proper file name, the browser names the file after the page, download.php, even though its contents are a PDF. Your browser asks for GET /download.php?id=42 Web server runs the PHP sends back PDF bytes No file name sent → saved as "download.php" (the contents are still a normal PDF) Fix: rename it to "download.pdf" or let the checker above detect the right extension
Illustration: the PHP code stays on the server; what you downloaded is the document it produced, just with the wrong name.
PHP versionReleasedSecurity fixes until
8.5November 20, 2025December 31, 2029
8.4November 21, 2024December 31, 2028
8.3November 23, 2023December 31, 2027
8.2December 8, 2022December 31, 2026
8.1 and older—No longer supported

Other extensions you may meet: .phtml (PHP mixed with HTML templates), .inc (included PHP code), and old .php3, .php4 or .php5 files from early PHP versions.

How to open a PHP file: quick answer

Before you open a PHP file, decide what you need from it: the document a website meant to send you, the code itself, or the page the code builds.

Your situationWhat to do
You expected a PDF, invoice, photo, ticket or videoRename it to the right extension; the checker tells you which
You want to read the codeOpen it with Notepad, TextEdit (plain text) or VS Code
You want to edit a website or theme fileVS Code or another code editor, then upload it back
You want to see the page it makesRun it with PHP: php -S localhost:8000
Double-clicking shows code in the browserNormal: browsers don't run PHP (why)
You found an unknown PHP file on your serverCheck it for web-shell signs

Downloaded a .php file instead of a PDF or photo?

This is the most common reason people search for how to open a PHP file. Bank statements, invoices, school portals, ticket sites and forums often deliver files through a script such as download.php or attachment.php. When the server doesn't send the real file name (in the Content-Disposition header), your browser or phone uses the script's name instead. The file inside is fine; only the name is wrong.

  1. Find out what it is. Drop it into the checker. It reads the file's signature (for example %PDF for a PDF or PK for a Word or Excel file) and offers a download with the correct name.
  2. Or rename it yourself. Change .php to the extension you expected, most often .pdf, .jpg, .docx, .xlsx or .mp4.
  3. Open it with the usual app.

How to rename the extension

  • Windows 11: in File Explorer choose View > Show > File name extensions, then right-click the file > Rename and replace php with pdf. Confirm the warning. (Windows 10: View tab > tick File name extensions.)
  • Mac: select the file, press Command-I, change the name and extension under Name & Extension, and choose Use .pdf.
  • Android: in the Files app, open the file's menu (⋮) > Rename.
  • iPhone and iPad: in the Files app, touch and hold the file > Rename. Files often hides the extension, so the checker's download button, which saves a correctly named copy, is usually easier.
Illustration: Windows warns when you change an extension. For a PDF saved as .php, choose Yes.

The renamed PDF still won't open

Two things can go wrong on the website's side:

  • A server warning is stuck to the front of the PDF. Text like "Warning: Cannot modify header information…" is printed before the PDF data, so readers reject it. The checker detects this and offers a repaired PDF with the extra text removed.
  • The download is incomplete or empty. A 0-byte file, or a PDF without its end marker, means the session expired or the transfer broke. Sign in again and download it once more.

If the "invoice.php" came as an email attachment you didn't expect, be careful: a real company sends a PDF, not a .php. Check it here first; never open it as a web page and type a password.

View and edit PHP code

A PHP file is ordinary text, so you can open PHP files on any device with a text editor:

DeviceQuick lookProper editing
Windows 11/10Notepad (right-click > Open with)Visual Studio Code, Notepad++, PhpStorm
MacTextEdit (Format > Make Plain Text) or Quick Look (Space bar)Visual Studio Code, BBEdit, PhpStorm
LinuxText Editor, nano, vimVisual Studio Code, PhpStorm
iPhone / AndroidThe checker above, or any text-editor appEdit on a computer if you can

Editing a live website file? Download a copy, keep a backup of the original, edit it in a code editor that keeps the encoding (UTF-8 without BOM is the safe default; a BOM or stray space before <?php causes "headers already sent" errors), then upload it back.

Illustration: PHP code in a code editor. The browser would only receive the text "Hello, world".

Run a PHP file on your computer

To see what a PHP file actually does, you need PHP installed; a text editor can open a PHP file but never runs it. The command-line version is enough for most scripts, and it includes a small web server for testing pages.

1. Install PHP

  • Windows: download the current release ZIP from windows.php.net, unzip it (for example to C:\php) and add that folder to your PATH. Or install XAMPP, which bundles Apache, MariaDB and PHP.
  • Mac: install Homebrew, then run brew install php. macOS no longer includes PHP since macOS 12 Monterey.
  • Linux (Ubuntu/Debian): sudo apt install php-cli

2. Run it

# a command-line script
php script.php

# a web page: start PHP's built-in server in the file's folder
cd path/to/folder
php -S localhost:8000
# then open http://localhost:8000/yourfile.php in the browser

PHP's manual says the built-in server is for development and testing only, not for a public website. For full sites (WordPress, Laravel) you also need a database, so XAMPP, Laravel Herd or a Docker setup is easier.

Only run PHP code you trust. A PHP script has full access to your files and network. Never run a .php file that arrived by email or from an unknown download.

Why the browser shows PHP code or downloads the file

  • You opened it from your disk (the address starts with file://). Browsers don't contain PHP, so they show the text or offer to download it. Run it through php -S instead and open http://localhost:….
  • Your web server isn't running PHP for that file. On a live site, seeing raw PHP or getting a .php download means the PHP handler is missing or broken; that can expose passwords in config files, so fix it with your host right away.
  • The page uses short tags (<? instead of <?php) on a server where short_open_tag is off. Replace them with <?php.

Old PHP files and version errors

A PHP file written years ago may stop with a "Call to undefined function" error on a modern server. The checker's Checks tab flags the most common cases:

Found in the codeProblemFix
mysql_connect(), mysql_query()Removed in PHP 7.0Rewrite with mysqli or PDO
ereg(), split()Removed in PHP 7.0Use preg_match(), explode()
preg_replace('/…/e', …)Removed in PHP 7.0Use preg_replace_callback()
create_function(), each()Removed in PHP 8.0Use anonymous functions, foreach
match, ?->, #[...]Needs PHP 8.0+Upgrade the server's PHP
enum, readonlyNeeds PHP 8.1+Upgrade the server's PHP

Found a suspicious PHP file on your website?

Hacked sites often get extra PHP files ("web shells") hidden in upload, cache or theme folders. Typical signs: random names like wp-cache-x8.php, one huge line of scrambled text, eval(base64_decode(…)), or commands taken straight from $_GET or $_POST. The checker's Checks tab highlights these patterns without running anything.

  1. Don't open it in the browser on your site; that runs it.
  2. Download a copy and check it here. Note its date and folder.
  3. Assume more files are affected. Restore the site from a clean backup or reinstall the CMS core, themes and plugins from official sources.
  4. Change all passwords: hosting, FTP/SFTP, database, CMS admin accounts.
  5. Update everything and remove unused plugins; ask your host to scan the account.

Is it safe to open a PHP file?

Opening the code in a text editor or in the checker on this page is safe: the code is only read, never executed. The risks are elsewhere:

  • Running unknown PHP with the php command gives it full access to your computer.
  • A .php that's really a web page can contain a fake login form (phishing). The checker warns you when it sees a password field.
  • A .php that's really an .exe is a disguised program. Don't rename or run it.

Sources and technical references

Frequently asked questions

How do I open a PHP file?

Open it with any text editor, such as Notepad on Windows, TextEdit on Mac or Visual Studio Code, to read or edit the code. To see the page it produces, run it with PHP, for example with php -S localhost:8000. If you expected a document, check whether it's a renamed PDF.

Why did I download a PHP file instead of a PDF?

The website created the PDF with a PHP script but didn't send the real file name, so your browser named it after the script, such as download.php. The contents are usually a normal PDF. Rename the extension to .pdf, or let the checker on this page detect the right one.

How do I convert a PHP file to PDF?

If the .php is really a downloaded document, just rename it to .pdf; nothing needs converting. If it's PHP code, run it with PHP to produce the web page, open that page in a browser and use Print > Save as PDF to save the result.

Can I open a PHP file in Chrome?

Chrome can't run PHP, so opening a local .php file only shows the code or downloads it again. To see the page, run PHP's built-in server with php -S localhost:8000 in the file's folder and open http://localhost:8000/yourfile.php in Chrome.

How do I run a PHP file on Windows?

Download PHP from windows.php.net, unzip it and add the folder to your PATH, or install XAMPP. Then open Command Prompt in the file's folder and type php yourfile.php, or start php -S localhost:8000 and open the page in your browser.

Can I open a PHP file on my phone?

Yes, to read it. On Android or iPhone, use a text-editor app or drop the file into the checker on this page, which shows the code with colors. If it's a renamed PDF or photo, the checker offers a correctly named copy you can open normally.

Is it safe to open a PHP file?

Reading it in a text editor or in this page's checker is safe because the code is not executed. Running an unknown PHP script is not safe: it can access your files and network. Be careful with .php email attachments, which are often phishing pages.

What program opens PHP files?

Any text or code editor opens PHP files: Notepad, Notepad++, TextEdit, Visual Studio Code, PhpStorm or BBEdit. To execute them you need the PHP interpreter, which runs on its own from the command line or inside a web server like Apache or Nginx.

Why does my browser show PHP code instead of the page?

Either you opened the file directly from your disk, or the web server isn't configured to run PHP for it. Browsers never run PHP themselves. Use a local server such as php -S or XAMPP, or ask your host to fix the PHP handler on a live site.

Why won't an old PHP file run on my server?

It probably uses functions that newer PHP versions removed, such as mysql_connect (removed in PHP 7.0) or create_function and each (removed in PHP 8.0). Rewrite those parts with mysqli or PDO and modern equivalents, or ask a developer to update the code.

How can I tell if a PHP file is malware?

Warning signs include eval with base64_decode, long scrambled strings, system or shell_exec using $_GET or $_POST data, and odd file names in upload folders. The checker on this page flags these patterns, but it isn't an antivirus, so treat a match as a reason to investigate.

Last updated .