Installing PHP 5 on IIS in 5 simple steps


Yes, yet another PHP 5 installation guide. Why write one when there are already dozens of them out there? Well there are two main reasons: firstly I will be writing a lot of guides that require PHP to be installed and working and I will need something to point people to who have yet to install PHP. Secondly, I have read a lot of the guides out there and found that a good portion of them over complicate the process. It really should not be that hard or perplexing. In this guide we'll break down the process of installing PHP 5 on IIS into 5 simple steps that are easy to follow that works for IIS 5, IIS 5.1 and IIS 6.

NOTE: This guide is intended for use with PHP 5.2.x and below. A guide for PHP 5.3 and above will be published in the coming weeks.

So what are these 5 simple steps? In a nutshell, this is all you need to do to install PHP 5 on IIS;

  1. Download and Extract PHP 5 (we'll install PHP 5.2.1 on IIS 5.1 in this guide)
  2. Set your environment variables
  3. Set the PHP application mapping in IIS
  4. Configure php.ini
  5. Restart & Verify

Just before we continue I thought it pertinent to mention that it if you have already installed, or attempted to install PHP on your system then you must remove all traces of that install before continuing. If ANY PHP files exist anywhere else on your system that are accessible via the PATH environment variable, then it is very possible (even probable if the previous version of PHP was different) that you will have issues with hosting PHP content.

If you are wanting to install PHP 4, then the process is slightly more complex than installing PHP 5 and involves steps not covered in this guide. Not to worry as it is even easier for you. All you have to do is download the IIS Aid PHP Installer from this site and run the fully automated GUI installer. This installer will completely setup your PHP 4 environment, including all environment variables, IIS scriptmaps and IIS 6 web extension. The particular advantage of this installer is that it configures PHP 4 to use FastCGI mode as well as an Opcode cache for maximum performance. Expect to see some articles of just how much faster here in the future.

1. Download and Extract PHP 5

Nothing taxing about this, simply go to the PHP download page and download the latest PHP zip package from under the "Windows Binaries" section, along with the latest PECL Win32 binaries (do not get the ones marked "non-thread-safe" unless you plan to use CGI/FastCGI as otherwise you run the risk of a race condition). Save the PHP zip package to the directory where you will want to install PHP (e.g. D:\PHP), and then extract. Once extracted you'll see inside your PHP installation directory a sub directory called "ext". Save the PECL Win32 binaries download into it (e.g D:\PHP\ext), and then extract. Your PHP install directory should now contain all the content of your PHP zip package file, and your ext sub directory should contain the contents of your PECL Win32 binaries file. From here move back to the root of you PHP installation directory (e.g. D:\PHP) and create three directories, one called sessions, one called upload and one called log. In the log directory create a new file called php.log. First step licked.


Anonymous's picture

php.ini - missing line causes file download prompt and so on...

As far as I can see, the only thing that's missing is another change to the php.ini file regarding cgi.force_redirect setting.

The value MUST be set to zero. The php.ini file reads:

"cgi.force_redirect is necessary to provide security running PHP as a CGI under most web servers. Left undefined, PHP turns this on by default. You can turn it off here AT YOUR OWN RISK
**You CAN safely turn this off for IIS, in fact, you MUST.**"

Before I changed that setting, I had the same problem as a lot of people writing comments here: prompt for file download instead of displaying the page when using a web browser to connect to http://localhost.

I went through a couple of guides and none of them worked for my system. I am using Win XP with IIS 5.1 and I've tried to follow the manual installation steps described on the PHP site but it didn't work for me.

I just couldn't get FastCGI to work with PHP 5.3.3 no matter how hard I tried. I did everything by the book several times, nothing... When I chose php-cgi.exe for the executable - it worked but I wasn't sure if that's the way to go, so I decided to try it with your instructions.

Seems to be working fine, except for that initial

Anonymous's picture

how to put the file in website

i created phpinfo.php file using notepad.But how to place it in website and test using web browser.


Brashquido's picture


Hi John,

Usually you'd use something like FTP to upload your files to your webserver. Ultimatley it depends on how you connect to your server though. I'd recommend contacting your host to determine which method to use.

Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

IIS 5.1 being prompted to download .php

I spent a couple of days trying to get PHP 5.3 and FastCGI working with IIS 5.1. Symptom: it would hang, it would be blank, it would prompt for download depending on how I tinkered. The catch? I was doing the Mapping (.php to fcgiext.dll) correctly in IIS except applying it to the Web Sites folder instead of Default Web Site which is one below that in the IIS listing. I gather Default Web Site is the one that corresponds to where I have phpinfo.php test file with and I had been assuming subdirectories inherit the mappings automatically. Not so. I also had a problem with the OK button being grayed out when browsing for the mapping dll - and found you just need to click your mouse in the text box where the path is.

Anonymous's picture

Prompted to download the phpinfo.php file

I was having this problem with PHP Version 5.2.17, all I had to do was change the configuration and setting the php5isapi.dll on page 3 for each of my IIS website virtual directories that I have already made before installing PHP. (remember to restart IIS afterwards)

Thanks a great tutorial on PHP...

Anonymous's picture

Many thanks, Fantastic post.

Many thanks, Fantastic post. The best I have seen regarding installing and configuring PHP and MySQL for IIS.
I have installed everything as your instructions and it is working perfectly.

Although I do have an issue with OWA and activesync that you may be able to help with.

I am using SBS2003 on the IIS default web site.

Before installing Wordpress, PHP and MySQL, OWA and activesync were working fine. After installing Wordpress, PHP and MySQL, both OWA and activesync will not accept the login credentials. Index.php and PHP are affecting the default home documents of the default web site, everything is run through index.php.

To problem solve the issue, I have created two Home Directory folders for the default web site, one with the default setup (including default.htm, default.asp, index.htm, default.aspx) and the other with default setup AND the wordpress .php files. When I set the local path of the home directory to the folder that contains the .php files, our PHP web site functions perfectly BUT the OWA and activesync will not accept the login credentials. If I change the home directory to the folder that does NOT contains the .php files, OWA and activesync both function perfectly, but obviously our PHP web site does not function tech talks.

Any suggestions?????

Anonymous's picture

Top man

Great guide, thx a lot.

Anonymous's picture


This was a good guide to have PHP up and running on IIS, but I have done this all, but unable to get the PHP page to work. It shows the error as
"The page cannot be displayed
There is a problem with a program on the page you are trying to reach, and the page cannot be displayed."

I had this PHP running previously, until I re-installed the OS(XP), can't get this to work. I installed PHP, configured env variables, set the mapping to 'php5isapi.dll', set all the paths in php.ini, but no luck as well as no sensible errors. Can't decide, where to start searching. It is as if the PHP.ini is not being recognized, even though it is present only in 'wwwroot'. Tried mapping to 'php-cgi.exe', and force redirect to 0; still no go.

Need help or what am I doing wrong ?

Anonymous's picture


This is to add to my last post, where I was not able to get PHP running and got the error as 'The page cannot be displayed'.

This turns out to be execute permissions to be set in IIS. Somehow this keeps reverting back to 'none' when a php page is accessed, leading to the error. I guess if you have done everything right, checking the IIS configuration would definitely save a lot of hair and time rather than tampering with the PHP installation.

Also, the php.ini path seems to be bouncing around between C:/Windows and the installation path of the PHP. Not sure what is causing this though...

Brashquido's picture

IIS applications and/or multiple PHP installs?

Sounds like a bit of a headache. This sort of behaviour can be caused by a few things, my guess would be something like there being multiple PHP mappings in IIS as well as possibly multiple instances of PHP. Honestly you can spend hours trying to fault find these sorts of errors, and being a Windows 2000 server I'm guessing this is not a new install. My advice would be to start from scratch by doing a full uninstall of PHP on IIS, and in doing so you are ensuring your IIS environment is as clean as you can realistcally get it before installing PHP.

Dominic Ryan
6 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster