Unable to run PHP files on your browser? Here’s what you need to follow to run PHP files on your system.
We all are aware that PHP is a server-side scripting language. Therefore, to execute or to run a PHP file, we’ll need a server. This can be a web hosting server or our own desktop computer. So, in this article, we’ll see how we can convert our own system into a local server.
Initially, we’ll need to install an application that will work as a server. There are several applications available on the web, such as WAMP, XAMPP, LAMP, etc. So, we are going to install XAMPP for executing our PHP files.
Install XAMPP server
Click on the link to download XAMPP.
Select the installer according to your Operating System. Once the installer is downloaded, run the installation file. You don’t need to check any options, just click “Next” and let the installation process complete.
After the XAMPP server is been installed on your system, open the XAMPP Control Panel. This is where you’ll be starting your server and database.
As you open the control panel, all you need to do is just start Apache and MySQL. Apache is nothing but your server and MySQL is your database.
Now before jumping straight on the browser, first we’ll need to get familiar with some basic files and folders. As the server is installed, the default path is always the root directory where the OS is installed i.e. C Drive. Open the File Explorer on your system and you’ll see a folder named “xampp”.
Open the folder and you’ll able to see some more files and folders inside it. The folder we need to focus on is the “htdocs“. This is where you’ll need to reside/save your PHP files.
Once you have saved your files inside the htdocs folder, now its time to execute it.
Run PHP Files on Browser
Before executing the PHP files make sure that your server is ON. Or else, the browser will display error.
Now to run your PHP file, open your browser and enter the URL in the following format.
If you have a directory inside the htdocs folder then enter the URL is the following manner:
Therefore, this is how we can run or execute PHP files on our browser converting our system into localhost. Hope this was informative. Thanks for reading