How to run PHP files on localhost?

Thursday, June 4th, 2009

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

Avatar Image

Author Name :
Ranjith

Total : 0 Comment


Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup