How to run a PHP File
Setting up a developer environment for PHP is relatively easy. You need to just figure out how to run Apache, PHP, and SQL. The more popular way of doing this is installing an all-in-one package like XAMPP or WAMPP or whatever makes you sleep well at night.
Xampp: Download here
RUNNING THE PHP FILE
Follow these steps:
Open xampp control panel
If you're using Windows, type "xampp" (without the quotes) in your windows search and you will find "xampp control panel" or you can check your taskbar.
Click on the Start button in Apache and MySQL. If you have no errors, it means your Server is now up and running.
Go to your browser and type localhost. You should get that Welcome page from Xampp.
Now if you installed xampp properly, it should be on your computer's root folder (this could be Local Disk(C:) or Local Disk (whatever alphabet:) ). Follow these steps:
- Open the xampp folder
- Open htdocs (here's where you will keep your project folder). You can find the "Welcome to Xampp" web page by opening the dashboard folder and opening index.html. Apparently, to run your php projects, you have to place the project folder in htdocs.
Copy your work folder and paste it in the htdocs folder. For instance, my work folder (has the PHP Script and all other gibberish) is HNG-Script and in the image below, you can find it in the htdocs folder.
Finally, type localhost/your work folder name/. In my case, it is localhost/hng-script/. It might take some time, just wait.
That's how to set up a local server and run a PHP project on your computer.
- Install Xampp
- Start Xampp control panel
- Start Apache and MySQL
- Copy work folder to C:\xampp\htdocs
- Type localhost:/work-folder on your browser
Having issues? Check this troubleshooting guide.