How to run PHP files on localhost?

To run any php file you need to install Apache web server on your localhost. Also you need to install MySQL server for any database programming. You can install these separately or there is easy way to achieve the same by installing XAMPP.

XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use – just download, extract and start.

You have already learned to write a basic PHP program in the previous page. Here is that program.

         echo "MY First PHP Program";

Write this program in a notepad and save as firstprogram.php

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

Now to run this do the following steps.

  1. First download the xampp from
  2. Extract the file and double click the exe. This will install Mysql and Apache servers.
  3. Once the installation is complete, you will find XAMPP under Start / Programs / XAMPP. You can use the XAMPP Control Panel to start/stop all servers. Start Mysql and Apache servers.
  4. Copy firstprogram.php to C:/Program Files/XAMPP/htdocs/
  5. To run the php file, you just need to brows http://localhost/firstprogram.php

Note: You can also create any folders inside htdocs folder. For ex. create a folder called “test” and copy firstprogram.php to “test”, then the address will become http://localhost/test/firstprogram.php

23 Responses to “How to run PHP files on localhost?”

Leave a Reply