HomeApache Page 4 - Installing and Configuring Apache 2 on a Windows XP Machine
Getting PHP Working - Apache
Apache 2 represents quite a change from previous versions. If you have set up a previous version of Apache on a Windows XP PC, you will be interested in setting up the new version. Dan Wellman shows how to set up and configure Apache 2 on a Windows XP PC to give you a development environment that will allow you to test your PHP and other dynamic web technologies before taking them live.
To get PHP working, just visit www.php.net and download the PHP 5.0.4 installer. Run the installer and keep all of the defaults. That’s it; PHP is installed as a CGI application. All you need to do now is tell Apache that PHP is there. Open the httpd.conf file from the start menu and find the DirectoryIndex directive again. Add Index.php before index.html, because you’ll want the server to look for an index.php file before it looks for any other file type.
Now scroll down to the ScriptAlias directive and add the following line of code below the existing directive:
ScriptAlias /php/ "c:/php/"
The path is the path to the default PHP folder, which is generated during the installation of PHP. Change it if you chose to install to a different location. Next you’ll need to scroll quite a way down until you come to the AddType directives and add the following line of code directly beneath the last one:
AddType application/x-httpd-php .php
This will register files ending with a PHP extension to the list of available media types. Finally, scroll down to the Actions section. This section is commented out completely, so just add the following directive to a new line below the comments. Make sure there is not a hash symbol at the start of the line:
Action application/x-httpd-php "/php/php-cgi.exe"
This will tell Apache how to process the media type that you’ve just registered. Now save the httpd.conf file and restart Apache. The customary way to test a PHP installation is to make use of the phpinfo() function, which displays information about PHP and your system. In Notepad, type the following line of code, then save the file as index.php:
<?phpinfo()?>
Open a browser instance and again type http://localhost. You should now see the results of the phpinfo() function. PHP has now been successfully installed and Apache configured correctly for its use.