Configuring PHP 5 With Apache 2 On Windows

PHP or Pre Hypertext Processor is the one of the most used languages that has revolutionized the way programmers are developing websites. Running PHP on the Apache server helps you to run tests on a live environment and take any actions if required. This write-up guides you step by step on configuring PHP 5 with Apache 2 on Windows system, starting from installation to offering other alternatives as well.

  1. To use PHP on Windows with Apache, you should install the 2.2.x version on your system. To check if it has been installed- type http://localhost on the address bar of the browser and if the Apache Page appears, then it is confirmed.
  2. Extract the PHP 5 folder in the C drive and rename the file php.ini-recommended as
  3. Open the ‘conf ‘ folder after going to the Apache directory. Modify ‘httpd.conf ‘ and after that find LoadModule to replace it with the following:
    • For Apache 2.2.x: LoadModule php5_module “c:/php/php5apache2_2.dll”
    • For Apache 2.0.x: LoadModule php5_module “c:/php/php5apache2.dll”
  4. In Apache 2.2.x, search the section for “AddType” lines and add this line right before the section closing.
    • AddType application/x-httpd-php .php
  5. Add the following line anywhere in the file to let the server run the PHP executable every time a PHP script is encountered. Either add it in the comment block for ‘Action’ or in case of Apache 2.2.x, you can add it after the ‘AddType’ statement.
    • Action application/x-httpd-php “/php/php-cgi.exe”
  6. Modify DirectoryIndex index.html to DirectoryIndex index.php index.html.
  7. Start the Apache web server again.
  8. Create a PHP file having the following line and save the file in the root directory of the server with the name test.php.
  9. Now run Apache and open http://localhost/test.php (If you were able to configure successfully, then PHP information page is displayed or else the line is seen in the browser as text. In that case you can check the problem with the CommandPrompt window by running php-cgi.exe and the following line:
    • c:phpphp-cgi test.php

Another option is to use PHP Triad or WampServer, where configuring PHP and Apache is not required. If you can download the software then you get built-in support for MySQL, Apache and, PHP. Then you just need to install them and run.

PHP Web Development India

Categories: Web Development
One Comment

Add a Comment

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