I recently decided to experiment with hosting my own blog and after
looking at the various packages available decided that I wanted to use
WordPress. However, when it came to installing WordPress, I found that
there was a lack of really good documentation available if you wanted
to use IIS 6.0 as your web server. I also found quite a bit of
contradictory information regarding the installation of PHP and MySQL
on Windows 2003 – so I decided to write my own. This is the first of a
series of articles which will provide a complete walkthrough enabling
you to install PHP, MySQL and WordPress on an IIS 6.0 web server.

At the time of writing, the latest stable version of PHP is 5.1.4.
Start by downloading the zip package and the Collection of PECL modules
from here : http://www.php.net/downloads.php

#Note: You can use the Windows Installer package but it only
installs and configures the CGI version of PHP which is not the best
solution for an IIS web server; you should try to use the ISAPI version
– if you really want to know more about why this ISAPI is preferable to
CGI then I suggest you watch this IIS webcast :

TechNet Webcast: Comparing CGI and ISAPI in IIS 6.0 – Level 300


Install and Configure PHP

Start by creating a directory into which you will extract the
downloaded PHP files (php-5.1.4-Win32.zip). In this example I’m going
to use C:PHP as my installation directory. Then extract the files from
php-5.1.4-Win32.zip into C:PHP

If you need to use the additional PECL modules then extract the files from ‘pecl-5.1.4-Win32.zip’ into the C:PHPext directory.

Fig. 1

Next locate the file ‘php.ini-recommended’ in C:PHP and rename it to ‘php.ini’ (without the quotes of course)

Fig. 2

Open the ‘php.ini’ file and find the line which reads extension_dir
= “./” and change it to extension_dir = “C:PHPext”. This tells PHP
where the various extensions are located and as you can see the default
path in the ‘php.ini-recommended’ file which ships with PHP points to
the wrong location, so you need to change it.

You also need to add the location of your PHP directory to the
server’s PATH environment variable so that Windows knows where to look
for any PHP related executables (such as the PHP extension DLL‘s). To
do this Right-click on My Computer, click Properties and on the
Advanced tab click Environment Variables. In the Environment Variables
dialog box, under System variables highlight the Path variable and
click Edit.

Fig. 3

Add ‘;C:PHP’ (be sure to include the semi-colon separator) as shown
here and click OK. You need to re-boot the server for this change to
take effect.

Fig. 4

If you browse through the ‘php.ini’ file you will see an entry
describing the ‘cgi.force_redirect’ property. You will also see a
statement telling you that if you are using IIS you ‘MUST’ turn this
off. However, this only applies if you are using the CGI version of PHP
(i.e. php-cgi.exe) Since we are using the ISAPI version of PHP we can
safely ignore this – more details here : http://www.php.net/release_4_1_2_win32.php

You may have also seen various IIS and PHP HowTo guides which
suggest that you need to copy your ‘php.ini’ and some other PHP related
files to the C:WindowsSystem32 directory – this is not actually
necessary, as I shall demonstrate later in this walkthrough.

Configuring IIS

There are a few simple steps you need to take in order to get PHP working under IIS 6.0

First we need to create and then enable an appropriate Web Service
Extension so that IIS will both recognise and allow PHP files to be
processed by the appropriate script engine.

You can use the Internet Information Services (IIS) Manager GUI
method to perform this task (and most tutorials and guides you may find
tend to use this method) but there is a much quicker way of doing this;
namely using the ‘iisext.vbs’ Command-Line Administration Script, which
you will find in C:Windowssystem32 by default.

Assuming you are using the same directory structure as I am in this
walkthrough you can simply copy and paste the following line of text
and execute it at a command prompt from C:Windowssystem32 :

cscript iisext.vbs /AddFile c:PHPphp5isapi.dll 1 PHPISAPI 1 “PHP ISAPI”

Fig. 5

As you can see, this script creates a new Web Service Extension named “PHP ISAPI” with a status of Allowed.

Fig. 6

The IIS 6.0 Command-Line Administration Scripts are very powerful
and flexible tools and I would recommend using them wherever possible.
You can find out more about administering IIS from the command line
here :

Administering Servers from the Command Line in IIS 6.0


You can use the default web site for test purposes if you prefer but
in this example I am going to use a dedicated PHP test web site. I have
created a test web site which has a home directory of C:test. The next
step is to create an Application Extension Mapping at the web site
level for PHP scripts. You can perform this step using the MMC GUI but
I am going to use AdsUtil.vbs for this demonstration.

There is actually a good reason for doing this – as I intend to use
this web site purely for PHP testing I can remove any unused
application mappings on my PHP web site, such as .idc, .shtml and .asp,

I can achieve this simply by executing the following script from a command prompt at C:InetpubAdminScripts :

cscript adsutil.vbs set W3SVC/87257621/root/Scriptmaps “.php,C:PHPphp5isapi.dll,5″

Fig. 7

Running the above command has the effect of setting the Scriptmaps
metabase property for Web Site ID 87257621 so that only the .php
Application Extension Mapping is enabled.

Fig. 8

However, as you can see, this script doesn’t just add the PHP script
mapping to the web site – it removes any existing mappings as well – so
only use the above command if you are sure that you want to remove any
existing application mappings on your chosen web site. In other words,
if you run the above script against a web site which hosts any other
applications (such as ASP) then it will break that site’s functionality
and you will need to repair the application mappings manually. So only
do this if you are sure that you only want to run PHP on your chosen
web site.

#Note – if you are using your web site for development and you need
to retain any existing application script mappings then you can use an
excellent script provided by IIS guru David Wang which provides far
greater flexibility than Adsutil.vbs. You can find David’s script here :


OK, now we are ready to test our PHP installation. Start by creating a
simple PHP test file. Open Notepad on the server and copy the following
line into a new text file :

<?php phpinfo(); ?>

Save the file as index.php in the root of the test web site. Next
create a new default document type of index.php on the test web site
(this step is optional but it just makes browsing a bit easier)

Fig. 9

Browse to http://localhost (or http://localhost/index.php) and you should see the standard PHP configuration details page.

Fig. 10

However, if you look carefully at the above page you will notice it
is indicating that my ‘php.ini’ file is actually located in
‘C:WINDOWS’ even though there is no such file in my C:WINDOWS
directory. This is because the ‘php5isapi.dll’ file is actually
compiled with this location as its default value. A number of existing
PHP and IIS tutorials suggest that you should copy the ‘php.ini’ file
to the C:WINDOWS directory – but what if you don’t want to do that ?

Well, you don’t have to because PHP allows you to actually configure
a custom value for the ‘php.ini’ file location. There are a number of
ways to do this but perhaps the simplest is to configure the PHPRC
environment variable. Further details of how this works can be found
here : http://uk.php.net/configuration

To demonstrate how this works I am going to create a new folder
called ‘C:inifile’ and instruct PHP to read its configuration data
from the ‘php.ini’ file in this location (in practice you may prefer to
leave your ‘php.ini’ file in the C:PHP directory)

In order to do this I need to create a new System environment
variable named ‘PHPRC’ and provide the appropriate values. Right-click
on My Computer, click Properties and on the Advanced tab click
Environment Variables.

Fig. 11

In the Environment Variables dialog box, under System variables
click New. In the New System Variable dialog box type PHPRC for the
variable name and then enter the desired path to your ‘php.ini’ file’s

Fig. 12

Then click OK and you will see that a new System environment
variable has been created. In order for this to take effect you need to
re-boot the server at this stage.

Fig. 13

#Note – As an alternative, you can edit the registry and specify the
location of your configuration file. The main benefit of the registry
edit method is that it doesn’t require a re-boot – in testing this
method I found that any changes made would take effect once the
application pool serving the web site was recycled. However, choose
whichever method you feel most comfortable with and which fits your

Now if we browse http://localhost we can see that PHP is indeed
looking for its ‘php.ini’ file in the ‘C:inifile’ location which we
specified previously.

Fig. 14

And that’s it. You should now have a working installation of PHP
running on IIS 6.0. In the next article I will demonstrate how to
install and configure MySQL with PHPMyAdmin on IIS 6.0 and then I will
round off with a look at installing and configuring WordPress on IIS
6.0, which is what got me started down this road in the first place…