Friday, December 29, 2006

Setting up Apache-PHP on windows.

Step 1 : Downloading required files.

apache server binaries :
php binaries :

Step 2 : Install apache server.
Installing apache server is pretty much simple, and same as any other installation.
Just enter a network domain name and server name and some email id (
Then choose a installation directory : for reference i am using "C:\".
Note that a directory called apache2 will be created under C:\ .
So "C:\apache2\" is our directory.
Verify your installation by taking your browser and visiting or http://localhost.
You will see a page that confirms your apache installation.

Step 3 : Configuring apache
Now goto "C:\Apache2\conf\".
Open the file "httpd.conf" in any text editor.
Lines beginning with # are comments .. just read them to know how to tweak apache.
Change the DocumentRoot property to the folder which is the root of the site.

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot "C:/public_html/"

and after that a few lines under ..

# This should be changed to whatever you set DocumentRoot to.
<Directory "C:/public_html/">

# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
# The Options directive is both complicated and important. Please see
# for more information.
Options Indexes FollowSymLinks

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride None

# Controls who can get stuff from this server.
Order allow,deny
Allow from all


So C:\public_html\ is the server root. ie http://localhost/ = C:\public_html.
After this is done test the configuration by executing (command line):

C:\Apache2\bin>apache -t

If the syntax is right you will get a "Syntax OK" message.

Step 4 : Installing php
To install php, just extract or copy the "PHP" folder to C:\Apache2\ so that C:\Apache2\PHP is created.

Step 5 : configuring PHP
Copy the "php.ini-recommended" file from C:\apache2\php\ to C:\apache2\
Rename it to "php.ini".

Add 2 lines to the end of the file httpd.conf:

LoadModule php5_module C:/apache2/php/php5apache2.dll
AddType application/x-httpd-php .php

Test the php installation by making a php file.



Access the test.php (http://localhost/test.php) from your browser. If you see the source code, installation has failed.
If you see the php info file . PHP installation was successful.
Test the apache server configuration (mentioned above) to find out the error.

Stuck ? leave a comment...


Anonymous said...

You can also get a built and configured Apache, PHP, MySQL setup under one of the WAMP distributions, such as the Web-Developer Server Suite.

Arun Prabhakar said...

Please not that the PHP folder must be in a folder so that the entire location does not have any spaces.

For example :
C:/Program Files/Apache Group/Apache2/php/

will create problem.

So make sure its in a location like

so that it would not create problems in the httpd.conf file.

Raveendra Pai said...

thanks for helping Mr Arun