Updated: 3 September 2006
This tutorial will go through the steps necessary to install, setup and configure the Apache Web Server 2.0 with PHP 4.3.x or PHP 5.0.x on a machine running Microsoft Windows.
As a guide, this tutorial will recommend the following installation folders:
Note: In general, this tutorial will refer to PHP4. PHP5 will only be mentioned for specific differences between PHP 4 and 5.
Download the latest versions of Apache 2.0.x and PHP 4.3.x (or PHP 5.0.x).
Apache HTTP Server : Win32 binary (MSI installer)
http://httpd.apache.org/download.cgi
Example: apache_2.0.53-win32-x86-no_ssl.msi (4,689 Kb)
PHP : zip package
http://www.php.net/downloads.php
Example: php-4.3.10-Win32.zip (7,405 Kb)
Note: Be sure to get the proper installation packages (MSI installer for Apache and the zip package for PHP).
Run the Apache executable (MSI installer).
When you come to the Server Information page enter localhost for both "Network Domain" and "Server Name". You can enter any email address for "Administrator's Email Address" .
Install Apache for All Users, on Port 80, as a Service.

Note: Problems will occur if there is a conflict with port 80 (i.e. another web service, such as IIS, is already running). These problems can be corrected after installation by editing Apache’s httpd.conf file and specifying a different port. (See section Configure the port for Apache)
Note: If you do not want Apache running as a background service (i.e. taking up resources all the time), install Apache for the Current User, on port 8080 so that you can start Apache manually only when needed.
Continue with the setup, installing into the C:\www\ directory (create the directory if it does not exist). Accept all other defaults.
Unzip the PHP4 zip package into the C:\www\ directory and rename the C:\www\php-4.3.10-Win32\ directory to C:\www\php4\.
Unzip the PHP5 zip package into the C:\www\php5\ directory. (Unlike PHP4, the PHP5 zip package does not have a base installation folder.)
Note: The directories C:\www\Apache2\ and C:\www\php4\ will be referenced in the following section. If your installation folders differ from these, substitute appropriately.
PHP can be installed as an Apache module or as a CGI binary. The module option is recommended as it offers more flexibility and security than a CGI script.
Edit the httpd.conf file found in the C:\www\Apache2\conf\ directory.
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
...
DirectoryIndex index.html index.html.var index.php
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
...
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
# Dynamic Shared Object (DSO) Support
...
#LoadModule ssl_module modules/mod_ssl.so
LoadModule php4_module "C:/www/php4/sapi/php4apache2.dll"
Copy the file php4ts.dll from the C:\www\php4\ directory into the Windows System32 directory.
Note: If you upgrade PHP, you will need to recopy the php4ts.dll file.
# Dynamic Shared Object (DSO) Support
...
#LoadModule ssl_module modules/mod_ssl.so
LoadModule php5_module "C:/www/php5/php5apache2.dll"
PHPIniDir "C:/www/php5"
Where PHPIniDir specifies the path to your php.ini file (php5 root directory).
# ScriptAlias: This controls which directories contain server scripts.
...
ScriptAlias /cgi-bin/ "C:/www/Apache2/cgi-bin/"
ScriptAlias /php/ "C:/www/php4/"
# Action lets you define media types that will execute a script whenever
...
Action application/x-httpd-php /php/php.exe
# ScriptAlias: This controls which directories contain server scripts.
...
ScriptAlias /cgi-bin/ "C:/www/Apache2/cgi-bin/"
ScriptAlias /php/ "C:/www/php5/"
# Action lets you define media types that will execute a script whenever
...
Action application/x-httpd-php /php/php-cgi.exe
If Apache is having problems starting on port 80 (i.e. possible conflict with another web server), then the port should be changed. There are two sections that must be altered for proper communication with the new port.
# Listen: Allows you to bind Apache to specific IP addresses and/or
...
#Listen 12.34.56.78:80
Listen 8080
# ServerName gives the name and port that the server uses to identify
...
ServerName localhost:8080
Note: Any deviation from the default port (80) will require that the port is specified in the URL address. Example: http://localhost:8080/
Note: The directories C:\www\php4\ and C:\www\php5\ will be referenced in the following section. If your installation folders differ from these, substitute appropriately.
Copy the file php.ini-dist from the C:\www\php4\ directory into the Windows System32 directory.
In the Windows System32 directory, rename the file php.ini-dist to php.ini.
Rename the file C:\www\php5\php.ini-dist to php.ini.
Configuring resources, extensions, and other options in PHP will depend on the requirements of your project. The following is an example of the configuration necessary if you were uploading/resizing images and extracting EXIF data.
max_execution_time = 120 ; Maximum execution time of each script
max_input_time = 60 ; Maximum amount of time spent parsing
memory_limit = 10M ; Maximum amount of memory a script may consume
; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\www\php4\extensions"
;Windows Extensions
;Note that MySQL and ODBC support is now built in, so no dll is needed.
...
;extension=php_domxml.dll
extension=php_exif.dll ;Processing EXIF image data
;extension=php_fdf.dll
;extension=php_filepro.dll
extension=php_gd2.dll ;GD image library (create/resize jpegs)
;extension=php_gettext.dll
Note: Unlike previous versions, PHP5 does not have built in support for MySQL. The php_mysql.dll extension must be uncommented if you want to use MySQL.
Note: The directory C:\www\Apache2\ will be referenced in the following section. If your installation folder differs from this, substitute appropriately.
Note: The Apache Server must be restarted after making changes to the httpd.conf file. Make sure that Apache has been restarted. (Reboot Windows for absolute confirmation.)
Confirm that Apache is running, either as a service or manually in a console window. Check that Apache.exe is running in the Window's Task Manager.
If Apache is not running, the server can be started manually through the Window's program menu:
Programs > Apache HTTP Server > Control Apache Server > Apache
Test the url:
A browser window should popup displaying the welcome page for Apache.

If you see this page then the Apache server is setup successfully. If not, check the Troubleshooting section below.
Create a new text file with the following content:
<?
phpinfo();
?>
Save this file as phpinfo.php and place it in your Apache DocumentRoot directory (default: C:\www\Apache2\htdocs\).
Test the url:
A browser window should popup displaying the phpinfo.php page.

If you see this page then Apache with PHP is setup successfully. If not, check the Troubleshooting section below.
If you are experiencing problems, it is highly recommended that you go back through each step of the tutorial confirming that everything is setup correctly. Double check that all directory paths are specified correctly.
Note: Remember that when adding path values in the Apache configuration files on Windows, all backslashes such as C:\directory\file.ext must be converted to forward slashes, as C:/directory/file.ext.
Note: The Apache Server must be restarted after making changes to the httpd.conf file. Make sure that Apache has been restarted. (Reboot Windows for absolute confirmation.)
Note: Be sure to determine the exact nature of your error before trying to solve the problem. (Internet Explorer has the annoying habit of displaying relevant error messages in the title of the browser and not necessarily on the page itself.)
(OS 10048) Only one usage of each socket address (protocol/network address/port)
is normally permitted. : make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
<OS2>The system cannot find the specified. : no installed service named "Apache2".
Cause: Another application (web server) is using port 80. (The Apache server itself may already be running.)
Confirm that Apache is running, either as a service or in a console window. Check that Apache.exe is running in the Window's Task Manager.
This error usually means what it says, i.e. that the page being referenced cannot be found. If you receive this error when trying to connect to http://localhost/ or http://localhost/phpinfo.php, answer the following questions:
If you continue to experience problems or have further questions, feel free to contact us. Be sure to include the following information:
Hello ,
I have a problem running Php..
My apache server is running fine.
The following change were made in http.conf of apache2
LoadModule
#LoadModule ssl_module modules/mod_ssl.so
LoadModule php5_module "C:/WWW/php5/php5apache2.dll"
PHPIniDir "C:/WWW/php5"
AddType:
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps:
DirectoryIndex
#
DirectoryIndex index.php index.html index.html.var
I'm trying to run php 5 on Apache 2.0.54 on Windows XP
Apache is in c:/Program Files/Apache Group/Apache2
and Php is in c:/WWW/php5.
Pleae help
thank
Neelima.Neelima
I can't run my php script via my browser. My apache server is running fine, which is my local host and i just followed all the steps above for php5 to install it, but i don't know why it is not working. i have uninstall everything and then install it back 5 0r 5 times before just to make sure i was doing right, but i am getting the same error message "404 NOT FOUND". i have no idea what is going on. i have tried everything i could but nothing is working out. please help me to solve my problem. My listen port is 80, i have not changed any documentroot, no changes in virtualhost and i have saved the file phpinfo.php which contain the script into my C:\Program File\Apache2\htdocs\directory.please help me . thankyou
Omar