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

Anonymous's picture

Truely 5 Steps and very easy

Thanks for a superb article. Read a few articles on installing PHP on IIS but couldn't get it done. This one did the trick.

Anonymous's picture

Thanks a lot, its easy and

Thanks a lot, its easy and nice article
Only one extra thing i did i repeated first part of the 3rd step for my virtual directory as well.

Anonymous's picture

Mail

So, I've got everything working with PHP using this guide, and the site I made works great!

However, I was wanting to extend the site to add an email verification thing (you know, where you have to click some link emailed to you to verify you're a person), and I was using the 'mail' function PHP has.

This is the first time I've ever touched email from PHP, so this may have NOTHING to do with IIS (It's Windows 2000 Server, so using IIS 5.0) and entirely to do with my naivety, but I can't get email to work. Here is my code:

$mail = mail('someone@something.com', 'Hello, world!', 'This is a message from PHP. Neat, huh?');

if ($mail == TRUE) {
printp('Mail sent!');
} else {
printp('Mail fail.');
printp($mail);
}

How would I get this to work? The email address there was edited, in my actual page it's using my own personal email address.

I have IIS's SMTP service installed, but I don't know how to configure that either. I've never touched email serving before, so this could really be just me being naive.

Anonymous's picture

You are a star

Mate, I don't know how many years ago have you posted this useful information. I was trying to learn PHP through a book, but their instructions to install PHP in IIS didn't work and I was stuck. This was just WONDERFUL information from you. Thank you very very very much.

Anonymous's picture

Is PHP5.3 much different when installing?

Excellent tutorial. I am getting an error in phpmyadmin -
Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.5.12. This may cause unpredictable behavior.

So I guess I need to upgrade PHP, or downgrade MySQL. Do you agree?
Is there any chance you will be posting instructions for installing PHP 5.3 on IIS? I tried following the same instructions but it doesn't work :(

Thanks!

Brashquido's picture

No ISAPI in PHP 5.3

You'd be correct with your guess. PHP 5.3 is a pretty big change from PHP 5.2, one of the most notable changes was the ISAPI interface (which is used in this guide) was dropped from the package. I will be creating an install guide, however it may be a month or two off yet.

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

Anonymous's picture

Excellent Doc - Thanks

It solved my problem on IIS5. Step by Step useful instructions.

Thanks a lot,
Bala

Anonymous's picture

Getting error: Execute Access Forbidden

I did everything as stated here, but i am getting following error. Kindly help.
HTTP 403.1 Forbidden: Execute Access Forbidden
Internet Information Services

Anonymous's picture

PHP installed by WAMP to be configured in IIS 5.1

Hi,
Before i start following the tutorial, i would like to clarify whether I can follow these steps if I have the php instance installed in my system through WAMP.
I have the WAMP server running and my php directory resides in C:\wamp\bin\php\php5.3.5

Please guide me..
Thanks in Advance

-
Vathsan

Anonymous's picture

PHP5Isapi.dll is not available in PHP 5.4

i tried to do installation with this article, but unfortunate that the downloaded php 5.4 do not contain the php5isapi.dll file.
also the PECL Win32 binaries is not found on php download site.

how can i complete this installation! can anyone suggest?