How to run PHP files on a local computer using XAMPP

To run a PHP, it is enough to just install an Apache server on your local computer. In most PHP projects, MySQL is used as a database. PHPMyAdmin is required to manage the database. All are separate open-source software and installing this software one by one will be a difficult job for beginners. This is where XAMPP comes into the picture.  XAMPP is an easy to install Apache distribution containing Apache web server, PHP and MySQL bundled together. 

Download XAMPP from XAMPP’s official website. Select your operating system and click on the download button.

Download XAMPP from XAMPP's official website
Download XAMPP from XAMPP’s official website.

Wait a few moments after hitting the download button. Because the file is around 150 MB in size, it will take some time to download. After downloading the file, double click the executable file and follow the installation process. 

Xampp setup on Windows
XAMPP serve setup on Windows

Click on the Next button.

Xampp server setup on Windows
Select the required components to install

On this screen, some of the checkboxes will already be checked. It is enough to select Apache, MySQL, PHP and phpMyAdmin and click on the Next button. On the next screen, select the path where you want to install the XAMPP server. You can leave it as default c:\xampp. Click on the Next button.

Xampp installation on Windows
Xampp installation is in progress
Start Xampp server
Remove the tick mark and click the finish button

Once the installation is complete, remove the tick mark “Do you want to start the control panel now?” and click on the Finish button. We have to run the XAMPP control panel as administrators.

Step 2 – Run the XAMPP server and test it

Once the XAMPP installation is complete, you will need to run XAMPP as an administrator on Windows. To do that, click Start, find XAMPP Control Panel in your Programs list, then right-click and select Run As Administrator. Another option is to go to C:/xampp where you have installed the XAMPP server, run xampp_start.exe as administrator.

Run xampp as administrator
Run XAMPP as administrator

This will launch the XAMPP Control Panel.

Run Apache and MySql server on windows xampp
XAMPP Control Panel

First, run Apache and MySQL services on the left side of the Control panel. Observe the green tick mark. This will register the Apache and MySQL server as service and it will start the server on every system reboot. Now click on the Start button for both Apache and MySQL which should look like the below image.  You can track the green running status near to it.

Configure Apache and MySql server on localhost
Start Apache & MySQL in the XAMPP Control Panel

Now is the time to test the XAMPP server. Open http://localhost, if everything is good then it should open the page like the below image. 

Testing XAMPP on localhost
Testing XAMPP on localhost

Create your project folder inside C:/xampp/htdocs and upload the files. For example, create a folder called “project” inside C:/xampp/htdocs and upload a sample PHP file. Now go to the browser and open http://localhost/project. PHP file should open properly.

Creating a Database

We will create a MySQL database using the phpMyAdmin tool. Open http://localhost/phpmyadmin to launch phpMyAdmin.

phpmyadmin setup on localhost
PHPMyAdmin setup on localhost

Click on the tab Databases, enter the database name and click on create button. This will create a database. You can name the database whatever you want.

So, give it a shot and let me know if you have any questions in the comments section below. I’ll be happy to assist you!

Ranjith Kadamboor
Ranjith Kadamboor

Programmer with 15+ years of broad experience in Software Design and Development, Interested in Blockchain and Crypto.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.