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.
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 deviceOn this page
- Open PHP file online (free checker)
- What is a PHP file?
- How to open a PHP file: quick answer
- Downloaded a .php instead of a PDF?
- View and edit PHP code
- Run a PHP file
- Browser shows code or downloads it
- Old PHP files and version errors
- Suspicious PHP file on your website
- Is it safe?
- Related file extensions
- Sources
- FAQ
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.
| PHP version | Released | Security fixes until |
|---|---|---|
| 8.5 | November 20, 2025 | December 31, 2029 |
| 8.4 | November 21, 2024 | December 31, 2028 |
| 8.3 | November 23, 2023 | December 31, 2027 |
| 8.2 | December 8, 2022 | December 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 situation | What to do |
|---|---|
| You expected a PDF, invoice, photo, ticket or video | Rename it to the right extension; the checker tells you which |
| You want to read the code | Open it with Notepad, TextEdit (plain text) or VS Code |
| You want to edit a website or theme file | VS Code or another code editor, then upload it back |
| You want to see the page it makes | Run it with PHP: php -S localhost:8000 |
| Double-clicking shows code in the browser | Normal: browsers don't run PHP (why) |
| You found an unknown PHP file on your server | Check 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.
- Find out what it is. Drop it into the checker. It reads the file's signature (for example
%PDFfor a PDF orPKfor a Word or Excel file) and offers a download with the correct name. - Or rename it yourself. Change
.phpto the extension you expected, most often.pdf,.jpg,.docx,.xlsxor.mp4. - 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
phpwithpdf. 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.
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:
| Device | Quick look | Proper editing |
|---|---|---|
| Windows 11/10 | Notepad (right-click > Open with) | Visual Studio Code, Notepad++, PhpStorm |
| Mac | TextEdit (Format > Make Plain Text) or Quick Look (Space bar) | Visual Studio Code, BBEdit, PhpStorm |
| Linux | Text Editor, nano, vim | Visual Studio Code, PhpStorm |
| iPhone / Android | The checker above, or any text-editor app | Edit 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.
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 throughphp -Sinstead and openhttp://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 whereshort_open_tagis 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 code | Problem | Fix |
|---|---|---|
mysql_connect(), mysql_query() | Removed in PHP 7.0 | Rewrite with mysqli or PDO |
ereg(), split() | Removed in PHP 7.0 | Use preg_match(), explode() |
preg_replace('/…/e', …) | Removed in PHP 7.0 | Use preg_replace_callback() |
create_function(), each() | Removed in PHP 8.0 | Use anonymous functions, foreach |
match, ?->, #[...] | Needs PHP 8.0+ | Upgrade the server's PHP |
enum, readonly | Needs 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.
- Don't open it in the browser on your site; that runs it.
- Download a copy and check it here. Note its date and folder.
- Assume more files are affected. Restore the site from a clean backup or reinstall the CMS core, themes and plugins from official sources.
- Change all passwords: hosting, FTP/SFTP, database, CMS admin accounts.
- 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
phpcommand 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
- Supported PHP versions — php.net
- Built-in web server — PHP Manual
- Executing PHP files from the command line — PHP Manual
- mysql_connect (removed in PHP 7.0.0) — PHP Manual
- Backward incompatible changes in PHP 8.0 — PHP Manual
- PHP for Windows downloads — windows.php.net
- Content-Disposition header — MDN Web Docs
- macOS 12 removes PHP — Michael Tsai
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 .