Install PHP 5 on Apache in Windows
As Apache Module
To configure Apache to install PHP as a module, use an ASCII text editor to open the Apache configuration file, "httpd.conf". If you use Apache 1.x, the file is found in "c:\Program Files\Apache Group\Apache\conf\". Apache 2.0.x users can find it in "C:\Program Files\Apache Group\Apache2\conf\" while Apache 2.2.x users can find it in "C:\Program Files\Apache Software Foundation\Apache2.2\conf\". Basically, it's in the "conf" folder of wherever you installed Apache.
Search for the section of the file that has a series of "LoadModule" statements. Statements prefixed by the hash "#" sign are regarded as having been commented out.
If you are using Apache 1.x, add the following line after all the LoadModule statements:
If you are using Apache 2.0.x, add the following line after all the LoadModule statements:
If you are using Apache 2.2.x, add the following line instead:
Note carefully the use of the forward slash character ("/") instead of the traditional Windows backslash ("\"). This is not a typographical error.
If you are using Apache 1.x, search for the series of "AddModule" statements, and add the following line after all of them. You do not have to do this in any of the Apache 2 series of web servers.
Next, search for "AddType" in the file, and add the following line after the last "AddType" statement. Do this no matter which version of Apache you are using. For Apache 2.2.x, you can find the "AddType" lines in the <IfModule mime_module> section. Add the line just before the closing </IfModule> for that section.
If you need to support other file types, like ".phtml", simply add them to the list, like this:
Finally, for those using one of the Apache 2 versions, you will need to indicate the location of your PHP ini file. Add the following line to the end of your httpd.conf file.
Of course, if you used a different directory for your PHP installation, you will need to change "c:/php" to that path. Remember to use the forward slash ("/") here again.
If you are using Apache 1, you will have already placed your php.ini file in either the Windows directory or somewhere in your PATH, so PHP should be able to find it by itself. You can, of course, do the same if you are using Apache 2, but I find modifying the Apache configuration file a better solution than cluttering your c:\windows directory or your PATH variable.
Running PHP 5 as a CGI Binary
If you have configured PHP 5 to run as an Apache module, skip forward to the next section. This section is for those who want to configure PHP to run as a CGI binary.
The procedure is the same whether you are using the Apache 1.x series or one of the 2.x series.
Search for the portion of your Apache configuration file which has the ScriptAlias section. Add the line from the box below immediately after the ScriptAlias line for "cgi-bin". If you use Apache 2.2.x, make sure that the line goes before the closing </IfModule> for that <IfModule alias_module> section.
Note that if you installed PHP elsewhere, such as "c:\Program Files\php\", you should substitute the appropriate path in place of "c:/php/" (for example, "c:/Program Files/php/"). Observe carefully that I used forward slashes ("/") instead of the usual Windows backslashes ("\") below. You will need to do the same.
Apache needs to be configured for the PHP MIME type. Search for the "AddType" comment block explaining its use, and add the AddType line in the box below after it. For Apache 2.2.x, you can find the AddType lines in the <IfModule mime_module> section. Add the following line just before the closing </IfModule> for that section.
As in the case of running PHP as an Apache module, you can add whatever extensions you want Apache to recognize as PHP scripts, such as:
Next, you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following somewhere in the file, such as after the comment block explaining "Action". If you use Apache 2.2.x, you can simply add it immediately after your "AddType" statement above; there's no "Action" comment block in Apache 2.2.x.
Note: the "/php/" portion will be recognized as a ScriptAlias, a sort of macro which will be expanded to "c:/php/" (or "c:/Program Files/php/" if you installed PHP there) by Apache. In other words, don't put "c:/php/php.exe" or "c:/Program Files/php/php.exe" in that directive, put "/php/php-cgi.exe".
If you are using Apache 2.2.x, look for the following section in the httpd.conf file:
Allow from all
Add the following lines immediately after the section you just found.
Allow from all
Configuring the Default Index Page
This section applies to all users, whether you are using PHP as a module or as a CGI binary.
If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the "httpd.conf" file. To do this, look for the line in the file that begins with "DirectoryIndex" and adds "index.php" to the list of files on that line. For example, if the line used to be:
change it to:
The next time you access your web server with just a directory name, like "localhost" or "localhost/directory/", Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.
Restart the Apache Web Server
Restart your Apache server. This is needed because Apache needs to read the new configuration directives for PHP that you have placed into the httpd.conf file. The Apache 2.2 server can be restarted by double clicking the Apache Service Monitor system tray icon, and when the window appears, clicking the "Restart" button.