Here I will show how to install PHP and configure it with Apache. I am using Apache 2.2.6 and Windows XP. I would be installing PHP 5.2.5. It is assumed that you have read Installing Apache on Microsoft Windows.
1. Download PHP
PHP can be downloaded from http://www.php.net/downloads.php. Get the latest Windows Binary zip package for Apache. It should be something like php-5.2.x-Win32.zip.
2. Unpack PHP distribution
- Unzip to c:\php.
- Create a copy of c:\php\php.ini-dist and rename it to c:\php\php.ini.
3. Edit php.ini
- Edit php.ini file with notepad
- Comment out doc_root with ;
- Type doc_root = "c:\www" in the line just underneath. This address corresponds to the value of DocumentRoot in httpd.conf file of Apache. If you have set it to another value, use it instead of c:\www.
- Comment out extension_dir with ;
- Type extension_dir = "c:\php\ext" in the line just underneath.
Editing httpd.conf file
httpd.conf file is used to configure Apache. Go to
Start > Apache HTTP Server 2.2.6 > Configure Apache Server > Edit the Apache httpd.conf Configuration File
At the end of the file, type the following:
# Configuring PHP5 for Apache
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php"
- The first line specifies the location of the .dll file which links Apache to PHP. Depending on your software version the name of the file would be different. However, it should have the format php5apache2_x.dll. Use the filename found inside your c:\php folder.
- The AddType directive specifies which mime type should be used for a given file extension
- PHPIniDir specifies the location of your php.ini file
- Do to DirectoryIndex found inside
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Order matters. Since index.php is placed before index.html, if both files were type, index.php would be displayed by default. So if you just type, http://localhost, index.php would display. If it doesn't exist, index.html will be displayed.
Moment of Truth
Create file c:\www\index.php. Inside write some PHP code such as print "hello"; and save it. Restart Apache. Type http://localhost or http://localhost/index.php to see your file. If you see the code instead of the output, double check your modifications to the .ini files.