Installing Apache 2.0.* with PHP 5.* in Windows

Much documented as the above process is, a lot of people still get stuck in some part of the installation process or the other (me included). It is not a complicated process really, its just that there are some simple tips and tricks which people have learned the hard way and these tips and tricks are often not available to the newbie installer.

Apache and PHP are softwares which are actually meant for *nix environments but a surprisingly large number of Windows developers use these platforms as a basis of all web development. Given below are the steps to get a successfull installation of Apache and PHP on Windows.

Why Apache 2.0 and not the latest Apache 2.2.3? Because as of this date, Apache 2.0 has some dll inconsistencies with PHP 5.x versions. PHP 5.2.0 has been released but I havent tried installing it with the latest Apache. Hopefully the problems of incompatibilities have been solved this time round.

1.Installing Apache 2.0

  1. Download the msi installer version of Apache 2.0. Its simpler to install from that than the zip installer
  2. For Windows machines which are running PWS or IIS, you need to turn off the WWW service before running the installer, because Apache defaults to using port 80 for HTTP and it wont start if it finds that port 80 is already in use.
  3. Run the msi installer
  4. Installing the Apache webserver is very simple. Simply follow the default installation screens and you are done.
  5. If all went well, then you will see the red Apache icon in your taskbar.
  6. To test if apache is running, open your web browser and type http://localhost or http://127.0.0.1 . You will see different pages in both the urls but it means your Apache webserver is up and running.

2.Installing PHP

  1. Unzip the php zip file to a folder of your choice.
  2. Thats it. PHP is installed. Simple, huh? Unfortunately you cant fire up your browser and see any php files running just yet. PHP need to be linked in with Apache before php pages start to run on your machine.

3.Changes to Apache 2.0 configuration

  1. Open up httpd.conf file in a text editor. This file exists in the /conf subdirectory of the folder in which Apache is installed.
  2. Do a text search for ‘AddType’. You will find lines which start with the AddType directive. After the last AddType line add these two lines:
    1. #php 5
    2. AddType application/x-httpd-php .php
    3. This tells Apache to handle php files as a registered application type.
  3. Do a text search for ‘DirectoryIndex’. Most likely this line will show as :
  4. DirectoryIndex index.html index.html.var
  5. This means that if a url does not specify a file, but only a folder, then the default page to load will be index.html. We want to change it so that it loads index.php when no file is specified. So change it to :
    DirectoryIndex index.php index.html index.html.var
  6. So now index.php becomes the default file for all directories.
  7. Do a text search for ‘LoadModule’ in httpd.conf. After all the LoadModule lines add the following line (assuming php is in c:php) :
    1. LoadModule php5_module c:/php/php5apache2.dll

4.Changes to PHP configuration

  1. Copy php.ini-dist in the php folder to php.ini. If php.ini-dist is not present, copy php.ini-recommended to php.ini.
  2. Open php.ini in an editor.
  3. Do a text search for ‘extension_dir’ . Most likely this line will show as
    1. extension_dir = “./”
    2. Change that to the complete path where the php extensions are present. Generally this is the ext folder under the php folder. So an example of this would be :
    3. extension_dir = “c:/php/ext”
  4. Do a text search for ‘Windows Extensions’. Once there, scroll down till you find the lines starting with extension= . If you plan to use mysql then uncomment the line extension=php_mysql.dll.
  5. If you want to run php with mysql then copy a file called libmysql.dll from the php directory to the Windows sytem folder i.e /System32.
  6. If you want to use the curl module then asuming you have uncommented the extension=php_curl.dll in php.ini , copy ssleay32.dll and libeay32.dll from the php directory to the Windows sytem folder (System32).
  7. Copy the updated php.ini file into the Windows folder i.e c:windows or c:winnt.
  8. Copy php5ts.dll from the php directory into the Windows system folder ie.System32

5.Test php with apache

Make a page called test.php with the following line:

phpinfo();

and save it in the Apache default website folder ie. the htdocs folder under the Apache folder.

Type http://localhost/test.php

If all has gone well, then you should see the page run.

Let me know if I missed out on something. I would be glad to incorporate your inputs to this blog

1 Comment

  1. Sombody asked about how to enable mcrypt on php in windows XP
    so here the simple steps to do it …

    to enable mcrypt in php on windows , you have got to copy these files

    “libmcrypt.dll ” from the php folder and
    “php_mcrypt.dll” from the php/ext folder

    into the system32 folder of windows
    and then restart the apache server to enable it

    you can check if its enabled by using the function
    < ?php phpinfo(); ?>

    and save it in a file on your server and the access it through the browser to see if it shows the details about the mcrypt support

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.