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.

1
2
3
4
5
6
7
<html>
   <body>
      <?php
         echo "MY First PHP Program";
      ?>
   </body>
</html>

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

Now to run this do the following steps.

  1. First download the xampp from http://www.apachefriends.org/en/xampp.html
  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

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

  1. Is their any other way to run php on localhost by without downloading XAMPP

    Reply
  2. pranav

    Thanks very much to provide us all above things and guidelines. thanks

    Reply
  3. vishnusharma

    may i know how can run php program with system i have also run .net iis server please tell me php file not run i am trying more time

    Reply
  4. I have done the same thing for my signup.php page but i dont dont whether its working or not because after i run the file its giving me the page of main html file

    Reply

Leave a Reply