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

Installing PEAR on PHP5

Thanks for answering my pervious post. I reinstalled PHP4 and used your IIS-AID, however that did not work.

Uninstalled it again. and Installed PHP5 per your instructions. Worked like charm. However, the software i want to install is called VTCalendar, http://vtcalendar.sourceforge.net/index.php, I followed the instructions but can not get it to work. It requires PEAR to be installed as well.

I'm assuming PEAR is out of the box ready in PHP5, do you have any resources in installing PEAR on my WIndows 2003 Server?

Thanks
Ricky

BeachBoy's picture

What's the best extensions to enable for PHP on IIS?

Dominic,

I'm curious about one thing regarding extensions for PHP 5.2.3 on Windows XP using IIS 5.1... Which extensions do you recommend that someone enable in their PHP.ini file for the best functionality for most PHP based applications? I plan to use Drupal 5.2 as mentioned in my previous post, as well as some other tools (CiviCRM, a OpenID server, etc...). If you could recommend some extensions (or write a article on the subject), it would be very helpful to me and others interested in using PHP 5. Also, please explain what the Pear libraries are used for, and where do we (I) download them, install them in PHP and so on.

Thanks in advance
~ BeachBoy

Brashquido's picture

@ Ricky Installing PEAR

@ Ricky

Installing PEAR should be as simple as opening up a command prompt, navigating to the root directory of your PHP install, and executing the go-pear.bat batch file. From there just answer the questions and you should be set.

@ BeachBoy

Enabling PHP extensions for IIS when using PHP as an ISAPI module is where things get a bit tricky, and you certainly do not want to go enabling PHP extensions unless there is a specific need. This is because a lot of PHP extensions are designed with the *nix multi process model in mind, where Windows/IIS uses a multi threaded model. This can cause major stability issues when using PHP extension that are not thread safe on Windows. Currently the only real viable way around this with PHP5 is to configure IIS to use PHP in CGI mode which is not effected by this, but this comes at the expense of a major performance hit (even using the new non thread safe binaries that significantly increase PHP CGI performance). If a PHP application requires a specific PHP extensions, then it will usually specify what one(s) it needs in its requirements documentation.

As for PEAR, have a read through the Wikipedia entry for more details. The PEAR package manager is included with the Windows distribution packages for PHP, and can be installed as per instructions above for Ricky. Again, if a web app requires a particular PEAR package, then that should be specified in the requirements documentation.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

BeachBoy's picture

Woohoo! It works like a charm (so far)

Dominic,

Thanks for a very easy to follow install guide... I've now got my IIS Server setup for PHP, and I'm quite happy with the results. I don't know if anyone has mentioned this, but if you wish to use a PHP app that has an index.php file, you should set the Default Document section of the IIS manager to reflect this. Make sure you add it, then move it up the list before the iisstart.asp entry.

Regarding Pear, I'll be adding that as I need it. Now I'm off to test Drupal...

~Beach Boy

Anonymous's picture

Thaks for a great guide!!!

But i followed it to a tee. However when i pull up the http://localhost/phpinfo.php page it doesn't error out it just says done in the left corner of IE. It does nothing. Any Ideas? Thanks again for the detailed guide and any help you can offer.

Jason

Brashquido's picture

Ok, what version of windows

Ok, what version of windows are you using? Can you scan your IIS logs for phpinfo.php and post back the entire line if you find it?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Great GUIDE!! Just facing one problem...

Hi Brashquido,

Thanks for the wonderful step-by-step guide. I'm still having a problem with the prompt that wants to download the file rather that run it. I've checked the MAPPING settings and they are correct. I also tried using:
http://localhost:8020/phpinfo.php BUT it wants to save the file. Other html files work fine though.

Any ideas?

Thanks

Anonymous's picture

PHP Code shows up in browser!!

Thanks for the great guide, but when I try the PHP test the code shows up instead of the page. It's like nothing gets processed.

I tried the small code you suggest and the same thing happens.

Thanks in advance

Anonymous's picture

Great Guide!!

Thank you very much!! This has been my 5th attempt at configuring IIS and PHP. After all the rubbish advice from the first search results in google, i hit the next button about 15 time and found your site! Thank goodness!!

Again, many thanks for the advice!

Damien

Brashquido's picture

If you are being prompted to

If you are being prompted to download php files rather than them being processed, then I'll stongly suspect that it is your application mapping. I know you said you've check it, but it is the only way I've ever been able to reproduce this problem. Double and triple check this, and if the problem continues feel free to send me a private message or use the website contact form to get in contact me as if the application mapping is not the issue I am as keen to find a resolution as you are.

As for php code being displayed in the browser window rather than being processed, then double check that your php code is enclosed in the proper php tags. Your php scripts may also be configure to use short tags, and if so you'll need to enable the short tag option in php.ini or modifiy your scripts to use the full php tags.

Thanks for the kudos Damien, glad to know the guide helped :)
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster