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

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

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

  2. pranav

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

  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

  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

  5. shadab ahmad

    The XAMPP suite of Web development tools, created by Apache Friends, makes it easy to run PHP (Personal Home Pages) scripts locally on your computer. Manual installation of a Web server and PHP requires in-depth configuration knowledge, but installing XAMPP on Windows only requires running an installer package. This package installs not only a Web server and PHP but also MySQL, FileZilla, Mercury, Perl and Tomcat.

  6. Multitechnosys

    It has been a long time since I’ve read anything so informative and compelling. I’m waiting for the next article from the writer. Thank you.


Leave a Reply