Installing and Setting up Apache 2.2 series with PHP 5 on Windows

Update: Please see the new post about Installing Apache, PHP, MySQL on Windows XP (for XP users) or Installing Apache, PHP, MySQL on Windows Vista or Windows 7 (for Vista and 7 users) for a better and more detail guide

Previously i wrote a how to guide on installing Apache 1.3 on Windows machine. But it seems that some people prefer to use the new Apache 2.2 series instead of the old httpd 1.3 series which is not good when used on production system (read: if you allow anyone to access your webserver), beside the apache website itself tell you this :

the older 1.3 series was never designed to run on Windows, but that support was ‘hacked in’, introducing a large number of potential thread saftey issues and other confirmed problems.

And that’s why i choose to create the apache guide again but this time it is using the 2.2 series, and of course this guide tell you on how to setup your apache server with php 5 manually not using an all in one package. And here’s the guide :

Requirements :

1. Apache 2.2.x : At the time i wrote this guide, the latest stable version is 2.2.26 (btw get the non-ssl version unless you plan on using ssl)

2. PHP 5.2.x : 5.2.4 is the latest stable version when i wrote this (get the zip version, not the installer)

And here are the steps :

Note : in this example i’m using the default installation path for Apache 2.2

1. Install Apache 2.2 until below screen appears and use this information (or adjust it to your liking) and then continue the process until finished :)

Apache Installation Process

2. To make sure Apache is working now you need to open your browser window and type http://localhost as the address, and if you get the same message like below image that mean apache is working

Apache Default Page

3. Thanks God the Apache seems to work … but now you’ll need to configure apache so it’ll recognize the php files and can parse the php files correctly. And the first thing you should do is extracting the PHP zip archive somewhere, and in this example i extracted the php 5.2.4 files into C:\PHP-5

4. After finished with the extraction process, now you just need to go to your Apache installation path, and then open httpd.conf which is located under the conf directory using your favorite text editor. Btw if you installed apache using the default path, here’s what the apache directory structure looks like

Apache 2.2 Path

5. In order for apache to parse the php files correctly, first you need to Load the PHP5 module into the Apache, and to do this you just need to add below line to your Apache httpd.conf (after the last line of the loadmodule section) :

LoadModule php5_module "c:/php-5/php5apache2_2.dll"

Note : Adjust the php path accordingly if you extracted it into other directory

And here’s the image :

Php loadmodule apache 2.2

5.1 Now you need to search for (use your text editor built-in search function) :

<IfModule mime_module>

and then add these lines inside that directive (before the closing </IfModule> for mime_module )

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

6. After finished with the above process, now you’ll need to configure apache so it’ll check the existence of index.php by default too instead of just checking the index.html only for the default index filename, and here’s how to do it

The default configuration from Apache 2.2 :

<IfModule dir_module>
DirectoryIndex index.html

The modified version :

<IfModule dir_module>
DirectoryIndex index.html index.php

Notice the difference ? i’m pretty sure you’ll notice it right away … but like everyone knew that a picture worth a thousand words (read: because my English language is bad), so here goes the picture

Apache directory index

7. Now we are done with the httpd section, now we need to configure php. Here are how to do that :

7.1 Copy php.ini-recommended from your php5 directory into C:\Windows (or your windows path) and then rename it into php.ini

7.2 Open the php.ini file using notepad and change the extension_dir as shown on below image :

Php extension dir

7.3 Now you need to copy some dlls from your php 5 directory into C:\Windows\System32 :

Php dlls

Im pretty sure that you can’t read the filename from the above image, but don’t worry because all you have to do is just copy all the dll files at the root of your php directory into your system32 directory except those that contains php5*.dll in its filename

8. Now we’ve configured php, apache … but what else do we need ? of course we need to make sure that php really working and apache can parse it without problem, so we need to create a php test page first, here’s how to do it :

8.1 Create a file named test.php inside C:\Program Files\Apache Software Foundation\Apache2.2\htdocs (because that’s where the default document root path of your apache)

8.2 Add below line to the test.php file like shown on below image, then save and close the notepad

Create php test file

9. Okay … finally we’ve reached the final stage !!! now you just need to open command prompt and type like below image :

Apache 2.2 restart

If you can’t read what you should type from the above image, actually you just need to type :

net stop apache2.2 && net start apache2.2

to restart your apache 2.2 process

10. Now after finished restarting the apache process, we need to open the browser window and point to http://localhost/test.php

Php test page

If you see something shown like on the above image, that means Apache and PHP is working on your system

Congrats … now you’ve got apache and php 5 working on your system the only thing left is … adding mysql support (if you plan on using a registration page for your Mangos Server or other private server), and to do this you just need to remove the ; from the extensions, for more information, you can download the sample php.ini and httpd.conf as a supplement for this short how to guide

Hint : Compare the sample php.ini file you’ve downloaded with the default php.ini file from the php.ini files included in PHP archive (in this case you can find it on your windows directory)

Hopefully i didn’t miss anything, but if you do notice that i miss something, please let me know so i can fix it or add it :)

Thanks to Al for the suggestion :)


Note: Comment may not appear right away.

307 comments on “Installing and Setting up Apache 2.2 series with PHP 5 on Windows

  1. Thanks.
    After reading tons of ‘try this’, ‘try that’, and ‘you might also’…
    I found your instructions.
    Works perfect.

  2. Hi, Im looking to install Apache2.2 for Joomla from http:/ but it doesnt have apache 2.2 to install.

    Please help!

  3. Nice article.It worked fine for me..Thank You.
    Please let me know how to connect this to an oracle database

  4. Hello friend, I really find your tutorial helpful. But Apache2.2 now won’t start after installing PHP. Thanks. What should I do?

  5. Great docs, thank you…

    the addtype line should be two lines:

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

    1. Thank you very much, although well … this is the old version (i believe i already put the links to the new version at the top of this page) :D

      Anyway for the addtype line (and many other lines that use code tag) being displayed as a single line.

      It’s because several weeks ago i changed anything that is using code tag into using pre tag (automatically not manually), and because i was using br tag without new line back then, the new pre tag caused it to be displayed as a single line after it has been changed into pre tag

      In another words it’s something like this:

      – Previously:

      <code>AddType application/x-httpd-php .php<br />AddType application/x-httpd-php-source .phps</code>

      And it’s displayed as multiple lines (correct)

      – After switching to pre tag

      <pre>AddType application/x-httpd-php .php<br />AddType application/x-httpd-php-source .phps</pre>

      Displayed as a single line (wrong)

      Thank you very much for reporting this :)

  6. I’m trying to put php and apache working but it’s getting a nightmare. I follow your tuturial and others but the problem seems to be on this part: LoadModule php5_module “c:/PHP/php5apache2_2.dll”. When I try to restart the service this message pop up “request operation failed”. what I’m doing wrong? what´s the problem with this?

    Please Help me.

  7. To my amazement i discovered today, that php was not running on my apache, and remembered the whole story: changed notebooks, changed apache versions, didn’t come around to getting php to work…
    That’s when i found your tutorial – Just what i needed to get things working in 2min. Great! & Thanks!

  8. I did this and when pulling up the test page it wont load it will ask me if I wan to save or download the file???