Installing PHP 5 on IIS in 5 simple steps

Categories:

Set the PHP Application Mapping in IIS

Before IIS will parse PHP scripts, you must first create an application mapping for PHP. This application mapping basically tells IIS what ISAPI dll, or CGI executable to use to process files of a certain file extension (in this case .php). There are two ways in which we can do this, via the command line or via the IIS MMC snap in. I'm going to show you how to do both.

As this is a universal PHP installation guide for IIS 5.0, 5.1 and 6.0 there are limited universal ways in which to add the PHP application mapping via the command line. What ever you do though do not use the adsutil.vbs script to try and add you PHP application mapping, at least not without understanding it's limitations. When you add/delete an application mapping with adsutil.vbs there is no way you can add/delete a single item at a time. So by using adsutil.vbs to add an application mapping you will effectively delete every other mapping at that level. However, what you can do is use David Wang's awesome chglist.vbs script to add the PHP application mapping without effecting existing mappings. You can download this script from David's old blog or from the bottom of this page. Once you have saved the script, simply open a command window and change into the directory that contains your script and type this in;

chglist.vbs W3SVC/ScriptMaps "" ".php,D:\PHP\php5isapi.dll,5" /INSERT /COMMIT

This will add the PHP ISAPI script map to the root of the IIS metabase, and any sites created after adding this script will automatically inherit it. If you want to add the PHP application mapping to a specific website then you will need to modify the W3SVC/ScriptMaps section of the command to suite. If none of this makes sense at all, don't worry because all this can be done using the GUI as well which we will cover now.

  • Open the IIS MMC and right click on the Web Sites container (or click on any specific website you wish to add PHP to) and select the properties menu item


figure 6

  • Once the Web Sites Properties window opens select the Home Directory tab and click the Configuration button as shown below in figure 7.


figure 7

  • This will bring you to the Application Configuration window. Click the Add button at the bottom to add the PHP application mapping as shown below in figure 8.


figure 8

  • In the Extension field enter .php and then click on the browse button in the top right and select the php5isapi.dll file from inside you PHP installation directory (e.g D:\PHP). The default is to accept all verbs, but if you wish you can limit the verbs to tighten security for you PHP application mapping. Ensure that the Script engine and Check that file exists options as ticked and then press ok until you exit the properties windows.


figure 9

That is it, IIS should now be configured to serve PHP content. There is one exception though and that is if you are using IIS 6 then you will also need to configure a Web Extension, so if you are using IIS 5.0 or 5.1 you can proceed onto the next section. You can set the Web extension via command line using iisext.vbs or via the Gui. Using the iisext.vbs at the command prompt you'll need to type in this, but be sure to change the path to php5isapi.dll to suit your environment ;

iisext.vbs /AddFile D:\php\php5isapi.dll 1 PHP5ISAPI 1 "PHP 5 ISAPI"

To add the extension via the GUI, read on;

  • Open the IIS MMC and expand the server tree. Right click on the Web Service Extensions option and select the Add a new Web service extension option.


figure 10

  • In the Extension name field put in a descriptive name, such as PHP 5 ISAPI as shown below in figure 11. Make sure the Set extension status to Allowed option is checked and then click the Add button.


figure 11

  • In the Add file window click the Browse button and navigate to your PHP installation directory and select the php5isapi.dll file as shown below in figure 12. Then click the ok button until you exit back into the IIS MMC.


figure 12

All done, now your IIS 6 web server is all set to serve PHP content.

Comments

Brashquido's picture

Detailed on page 3 of the guide

Yep, not setting up your web service extension will get you every time. That is detailed at the end of page 3 in the guide. Good that you are all up and running now though!

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

Anonymous's picture

Thanks in Ton!

Thank you very much for the detailed step-by-step instructions guide!

I am an infant to PHP. I battled for a day in vain trying to get the setup working. Today, I stumbled upon this link - helped me a long way!

I had a few issues initially, when I kept getting "module" cannot be loaded/located issues. I was using 5.3, but later on, I switched 5.2.11 when all that you said worked!

Appreciate your deligence and selfless efforts in being of help to the rest of the folks who have been asking tons of questions. Really, it is heartening to see you replying to almost EVERY post in the thread!

Anonymous's picture

thank you

bravo good work
thank you very much^_^

Anonymous's picture

Getting Service Unavailable

I am moving my websites from a 32 bit server to a 64 bit server. IIS 6 on both machines. Win 2000 on old server with Win2003 on new server.
I copied the PHP folder over to the new server, not sure what the version is but the files are dated 8/23/06. I then followed the setup instructions from here.

I was getting a HTTP 500 error. I then executed this: cscript "c:\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1". Then I started getting the Service Unavailable on the web page, and not just for my PHP pages, also for my .Net (.aspx) pages.

I then executed "cscript c:\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0", to turn off the 32 bit support. I then started to get the "%1 is not a valid Win32 application" message. So I tried turning on the 32 bit support again, but am still getting the Service Unavailable message.

Do you have any suggestions?

Thank you,
Chris

Anonymous's picture

Getting Service Unavailable

I found the problem.
Since the .aspx pages use the .Net framework, I had to tell IIS to use the 32bit version of the .Net framework. The application pool would crash if IIS would try to use the 32 bit PHP with the 64 bit .Net.

To change IIS to use the 32 bit version of the .Net framework run this: %SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

Thank you,
Chris

Anonymous's picture

This could not be any easier to follow

For many years now I have worked with standard html and asp, recently got in to .Net but have always been interested in PHP after seeing some of the things done in PHP web pages.
After following this guide to install PHP on IIS (Yes still need IIS to serve other things) and restarted the server all came up and running.
Thank-you for taking the time to lay this out in the easiest format possible, excellent tutorial.
SoftMan.

Anonymous's picture

Is PHP needs SQL to Run

i just wandering if i install PHP5 on IIS is needs SQL to run probably

Brashquido's picture

Not necessarily, but probably

There are quite a few PHP applications that don't require any sort of database backend to store data. Having said that though there are probably more these days using a database backend than are not. You'll be best to use MySQL as almost all (open source at least) PHP applications will support this.

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

Anonymous's picture

PHP and MySQL Installation

Thank you!!

was trying to figure this out for the last 4 days with various installation guides. It just did not work. The two just didn't work together.

Thanks to your guides on both it finally works. THANK YOU!!!!

I'm sure I will have to do a lot of more reading on your site :)

Anonymous's picture

PHP and MySQL Installation

Thank you!!

was trying to figure this out for the last 4 days with various installation guides. It just did not work. The two just didn't work together.

Thanks to your guides on both it finally works. THANK YOU!!!!

I'm sure I will have to do a lot of more reading on your site :)