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
- Download the msi installer version of Apache 2.0. Its simpler to install from that than the zip installer
- 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.
- Run the msi installer
- Installing the Apache webserver is very simple. Simply follow the default installation screens and you are done.
- If all went well, then you will see the red Apache icon in your taskbar.
- 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.
- Unzip the php zip file to a folder of your choice.
- 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
- Open up httpd.conf file in a text editor. This file exists in the /conf subdirectory of the folder in which Apache is installed.
- 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:
- #php 5
- AddType application/x-httpd-php .php
- This tells Apache to handle php files as a registered application type.
- Do a text search for ‘DirectoryIndex’. Most likely this line will show as :
- DirectoryIndex index.html index.html.var
- 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
- So now index.php becomes the default file for all directories.
- Do a text search for ‘LoadModule’ in httpd.conf. After all the LoadModule lines add the following line (assuming php is in c:php) :
- LoadModule php5_module c:/php/php5apache2.dll
4.Changes to PHP configuration
- 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.
- Open php.ini in an editor.
- Do a text search for ‘extension_dir’ . Most likely this line will show as
- extension_dir = “./”
- 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 :
- extension_dir = “c:/php/ext”
- 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.
- 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.
- 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).
- Copy the updated php.ini file into the Windows folder i.e c:windows or c:winnt.
- 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:
and save it in the Apache default website folder ie. the htdocs folder under the Apache folder.
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