What Is a PHP File?
Tim Fisher has more than 30 years’ of professional technology experience. He’s been writing about tech for more than two decades and serves as the SVP and General Manager of Lifewire.
In This Article
What to Know
- A PHP file is a PHP source code file.
- Open one with Visual Studio Code, or any text editor.
- Convert to PDF with FPDF.
This article describes what a PHP file is and how it’s used in the context of a web server. We also look at how to open a PHP file on your computer.
What Is a PHP File?
A file with the PHP file extension is a PHP source code file that contains Hypertext Preprocessor code. They are often used as web page files that usually generate HTML from a PHP engine running on a web server.
The HTML content that the PHP engine creates from the code is what’s seen in the web browser. Since the web server is where the PHP code is executed, accessing a PHP page doesn’t give you access to the code, but instead provides you the HTML content that the server generates.
Some PHP source code files use a different file extension like .PHTML, PHP3, PHP4, PHP5, PHP7 or PHPS.
How to Open PHP Files
Windows’ built-in Notepad program is one example of a PHP opener, but syntax highlighting is so helpful when coding in PHP that a dedicated editor is usually preferred.
Some text editors include syntax highlighting; see our list of the best text editors for some options, like Microsoft Visual Studio Code. Here are some other ways to edit a PHP file: Atom, Sublime Text, Coda, Codeanywhere, Programmer’s Notepad, Vim, and CodeLobster IDE.
While those programs will let you edit or change the file, they don’t let you actually run a PHP server. For that, you need something like Apache Web Server. See the Installation and Configuration guide on PHP.net if you need help.
Some .PHP files might actually be media files or images that were accidentally named with this extension. In those cases, just rename the extension to the right one, and it should open correctly in the program that displays that file type, such as a video player if you’re working with an MP4.
Still Can’t Open It?
Some file extensions look so similar that it’s really easy to mix them up, which can lead to using the wrong program to open the file.
For example, HPP includes all the same letters as PHP, but files with that suffix might be related to the Haluha Pearls program.
PPP is similar; there are a few programs that use this kind of file, one being PagePlus as a document file.
How to Convert a PHP File
To generate PDFs from PHP, see FPDF or dompdf.
See the documentation on json encode at PHP.net to learn how to convert PHP arrays into JavaScript code in the JSON format (JavaScript Object Notation). This is only available in PHP 5.2 and up.
You can’t convert PHP files to non-text-based formats like MP4 or JPG. If you have a file with the .PHP file extension that you know should have been downloaded in a format like one of those, just rename it from .PHP to .MP4 (or whatever format it should be).
Renaming a file like this isn’t performing a real file conversion but instead just allowing the right program to open the file. Real conversions normally take place within a file conversion tool or a program’s Save as or Export menu.
How to Make PHP Work With HTML
PHP code embedded in an HTML file is understood as PHP and not HTML when it’s enclosed in these tags instead of the common HTML tag:
To link to a PHP file from within an HTML file, enter the following code in the HTML file, where footer.php is the name of your own file:
You can sometimes see that a web page is using PHP by looking at its URL, such as when the default PHP file is called index.php. In this example, it might look like http://www.examplesite.com/index.php.
More Information on PHP
PHP has been ported to nearly every operating system and is completely free to use. The official website is PHP.net. There’s a whole documentation section on that site that serves as an online manual if you need help learning more about what you can do with PHP or how it all works. Another good source is W3Schools’ PHP Tutorial.
The first version of PHP was released in 1995 and was called Personal Home Page Tools (PHP Tools). Changes were made throughout the years, with new versions being released every few months.
Server-side scripting is the most common use for PHP. As described above, this works with a parser, web server, and web browser, where the browser accesses a server running the PHP software so that the browser can display whatever it is that the server is producing.
Another is command-line scripting, where neither a browser nor server is used. These types of PHP implementations are useful for automated tasks.
PHPS files are syntax-highlighted files. Some PHP servers are configured to automatically highlight the syntax of files that use this extension. This must be enabled by using the httpd.conf line.
Notepad or WordPad are usually the default programs associated with PHP files. You can change the default app by going to Start > Settings > System > Default apps > Choose default apps by file type, selecting .PHP, and choosing an app.
The wp-config.php file is usually located in the root folder of your website. The index.php file is a comprehensive template where you can find other PHP files in the template hierarchy.
Hash functions are a way to encrypt data without changing the original meaning. In PHP, the hash() function returns a hash value for the given data based on the algorithm.
How to Open a PHP File
This article was co-authored by wikiHow staff writer, Jack Lloyd. Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher.
The wikiHow Tech Team also followed the article’s instructions and verified that they work.
This article has been viewed 876,834 times.
This wikiHow teaches you how to open and edit a PHP programming file on your Windows or Mac computer.
Using Windows
- Go to https://notepad-plus-plus.org/download/v7.5.8.html in your computer’s web browser.
- Click the green DOWNLOAD button.
- Double-click the Notepad++ setup file.
- Follow the installation prompts.
Open Notepad++. If Notepad++ doesn’t automatically open after you finish installing it, open Start
Click Open… . This option is in the drop-down menu. Doing so brings up a File Explorer window.
Using a Mac
- Go to https://www.barebones.com/products/bbedit/ in your Mac’s web browser.
- Click Free Download in the upper-right side of the page.
- Double-click the downloaded DMG file.
- Verify the software if prompted.
- Drag the BBEdit icon onto the «Applications» folder.
- Follow any on-screen prompts.
- If this is your first time opening BBEdit after installing, click Open when prompted, then click Continue to continue with the 30 day trial.
Select your PHP file. Go to the location in which your PHP file is stored, then click the PHP file to select it.
- You may instead click Choose here.
- If you edit your PHP file, be sure to save it by pressing ⌘ Command + S .
Community Q&A
PHP file is running in xampp only when it is stored or copied in htdocs. I want to know why we aren’t able to run the php files in their current locations instead of changing their directories?
When you are running XAMPP, it is creating a web server which runs the file. The web server expects the files to be stored in the public directory, which is configurable, and defaults in the case of XAMPP to htdocs.
Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow
Yes, you could just click File > Print. Or you could copy it into another text editor and print it from there.
Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow
At the very least, you want a plain text editor, as PHP will be plain text. However, PHP is a programming language, so you are better off using a proper PHP editor which will make it look easier to read and edit. There are many available, depending on your operating system and budget, but if you just want to see what the file is, notepad will do.
Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow
Open PHP File
PHP files are used to store code written in Hypertext Language or PHP, a computer language used in web development to create dynamic pages.
PHP code allows to create a web page which can display according to several parameters, such as user location, type of client equipment (mobile, PC, etc). Often used to create spaces for members, it is associated with other code systems (CSS, HTML, etc.).
PHP files can include elements that offer additional features and functions for websites, such as contact forms, widgets and menus.
They are used to provide more functionality to web pages and work in conjunction with standard HTML files.
PHP files could be opened either for editing, debugging, adding code or for execution.
To edit a PHP file, just use a text editor. It can be Notepad, native to Microsoft Windows or it can also be a programming environment intended for this purpose, such as Visual Studio Community.
For example, to open the following PHP file, just right click on the file, ‘Open with’ and choose Notepad, as follows:
Doing so will show the code that would run on any well-configured PHP server:
If you want to create a HelloWorld.php, copy the code below and paste in a notepad file and save with the PHP extension:
It is necessary to emphasize that PHP files can only be ‘executed’ behind a configured server, if you are on Windows, you need to install a suitable PHP server, such as the XAMP which is an Apache server package which contains a PHP engine.
You can download the XAMP software from the following link:
Once installed, locate the content folder of the helloworld.php file created with the code above. Put it to the C:\xampp\htdocs folder and write the following in a browser:
And the following will be displayed:
That corresponds to the correct execution of the PHP file on a server, which is different from editing the file itself.
If you find problems opening a PHP file, it may be due to coding errors, malware damage or the file is corrupted, in any case, you must scan the file with an antivirus program, prior to editing/execution.
Open PHP file in Windows OS
- If you know the application which uses that particular PHP file use it to open it
- If you don’t know which application uses your PHP file try opening PHP file with PHP or text editor to see what is inside
- You can use Microsoft Visual Studio Code, Rapid PHP Editor, UltraEdit
- If the PHP file in question was downloaded from the web you may want to refer to the website from where it was downloaded. Typically PHP files are not expected to be downloaded from websites.
Get more information about how to open PHP file.
If you are not able to open file with certain file extension make sure to check if extension for the file is correct. It is possible that information in the file doesn’t match file extension.