Installing PHP 5 on IIS in 5 simple steps

Categories:

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.

Comments

Anonymous's picture

Excellent Guide

This is fourth set of instructions that I am looking at to get PHP to work. For some reason mmc.exe would stall each time I would attempt to use Window's IIS GUI to associate .php with the dll. Hence the IIS would not parse the php pages.

Running that VB script did the trick (I just had to modify the Root directory letter once the script was finished).

Thank you for such an excellent guide.

Brashquido's picture

No problem, glad it was

No problem, glad it was useful for you.

Anonymous's picture

PHP5 and MySQL5

Thanks for your good job. Your guide was a precious help. Thanks to it I could finally install PHP5 with MySQL5 on IIS. Really nice work!

Anonymous's picture

Is it just me?

Or are the graphics in this post broken?

Brashquido's picture

It's not just you, the

It's not just you, the images are not being displayed for some reason. Have a feeling that my server side HTTP cache might have an issue or two. I'll fix it tonight when I get home, so check back again in around 12 hours or so. Thanks for letting me know :)

*EDIT*

Should be working again now :)

Anonymous's picture

prompt for downloading .php file

Great tut!

but if i do all the steps and test it at the end, internet explorer prompt to download the .php file... :-S

It is in the root of the webserver, tried other locations too, but with the same result...

any explenation??

tnx

Brashquido's picture

Do you have a mime type

Do you have a mime type setup for PHP?

Anonymous's picture

To make things a little more clear

You can't do an include or a virtual include to test the php page for some reason that didn't work. Alll I did was made an <a href> tag that references the phpinfo.php page in the default.htm of the server directory and clicked on it to test the php implement.

Anonymous's picture

Spelling and Grammar

Check your spelling and grammar. Readers may loose confindence in the technical portion of the article if the non-technical language has spelling and grammars errors.

Anonymous's picture

Promt for downloading .php file

I get the same problem, I have made a href i another html file where I link to the php file, and yet it wants to download the file. I use IIS 5.1, followed all the steps.