PHP is a server-side scripting language. Unlike static HTML pages, it is not possible to view the web page created by a PHP script by opening the file in chrome.
PHP scripts must be saved on a web server with PHP services and must then be located by entering the web address in the address bar of the chrome browser, or by following a link in the same location.
How to run a PHP file in Chrome in 2021
Solution: Use XAMPP software
This software also provides PhpMyAdmin, a very useful application for the management of your databases, which can then be interfaced with your PHP pages.
Step by step instructions:
1. Download and install XAMPP – The installation is quite simple and straightforward. In this regard, I recommend leaving all the default and recommended settings.
2. Starting XAMPP – Once installed, you need to open the XAMPP Control Panel.
Once started, you will have a screen like this in front of you.
To view your PHP pages, you need to click on “Start” next to the Apache and MySQL modules (MySQL is useful if you need to take data from your database).
The operation will have been carried out successfully if the two modules have been started. And you will notice it if you see a situation like this in the Control Panel.
3. Create your PHP page. If you haven’t already, create a PHP page by opening a new file in an IDE (integrated development environment) text editor of your choice (such as SublimeText) and save it using the .php extension. Use the following outline structure:
<html> <head> </head> <body> <?php echo "Page content"; ?> </body> </html>
4. Place the PHP file on the server. Whether you are using a server on your computer or the web. Put the PHP file in the location you want it to be accessible from.
For XAMPP, you will need to put the PHP file in the .htdocs folder.
For web servers, you will need to make an FTP connection using a program like FileZilla or your web host control panel.
5. Find the path to your PHP page in your Chrome browser. Type the address in the Chrome address bar.
If you placed the file in the root directory. The page address will have the following structure, using its domain and file name:
If the PHP file is in a subdirectory, its location will have the following structure.
If the PHP file is running on a local server installed on your computer. The file location will have the following structure. http: //localhost/yourfile.php
6. Check the functionality of the page. The details of how you test your PHP will depend on its purpose.
Check first that the content is all that appears and is structured correctly in HTML.
If necessary, you can view the source of the HTML page using the browser menu. If the page contains user controls, test these thoroughly to ensure they work as you need.
As you have learned, running a PHP file directly in the Chrome browser is not possible. However, there is great software such as XAMPP that will help you to run and test your php file.
I hope this tutorial is a good starting point explaining how to run a PHP file in Chrome, or at least explaining how it can be done.
Hey guys! It’s me, Marcel, aka Maschi. I earn a full-time income online and on MaschiTuts I gladly share with you guys how I stay on top of the game! I run several highly profitable blogs & websites and love to speak about these project whenever I get a chance to do so. I do this full-time and wholeheartedly. In fact, the moment I stopped working an 8-to-5 job and finally got into online business as a digital entrepreneur, is problably one of the best decisions I ever took in my life. And I would like to make sure that YOU can get on this path as well! Don’t let anyone tell you that this can’t be done. Sky’s the limit, really…as long as you BELIEVE in it! And it all starts right here..at Maschituts!