Articles
Installing PHP 5 on IIS in 5 simple steps
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
- Once the Web Sites Properties window opens select the Home Directory tab and click the Configuration button as shown below in 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.
- 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.
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.
- 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.
- 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.
All done, now your IIS 6 web server is all set to serve PHP content.
- Add new comment
- 743316 reads






Comments
PECL have not been updated since PHP 5.2.6
Don't worry, you're not going blind. There is usually a PECL package release with each new version of PHP, however this has not been the case since PHP 5.2.6. What you will need to do is download the PHP 5.2.6 PECL package, which does work with PHP 5.2.9-2. You can get them from here;
PECL 5.2.6 Thread Safe
PECL 5.2.6 Non-Thread Safe
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster
i,ve got the problem getting
i,ve got the problem
getting error 404
new in PHP
please help
Monis
404 will be a permissions issue
A 404 error means the server was unable to find the file requested. This means it either doesn't actually exist, or the permissions on the file/folder are such that IIS is unable to actually see the file. Ensure that your IIS user account (IUSR_COMPUTERNAME by default) has at least NTFS read permissions to your php files.
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster
Very Helpful!
Here it is two years later, and this info is as relevant as the day it was written.
Extremely well written, and easy to follow. I had PHP up and running on my IIS server in about 20 minutes.
Thank you!
Many thanks
Thank you. Thank you. Thank you!
Been trying for a week now to get PHP up and running. Your's was the only walk-through I've found to make it soo simple and easy for a designer/developer to install PHP.
Thank you very much!
Josh
error_log -- advantage of filename over syslogs?
I'm setting up my PHP.INI and was wondering if there is an advantage to using a file for error logging over using the other option of 'syslogs'?
Personal choice
There isn't really an advantage of using one over the other, so it really comes down to a matter of personal choice and/or the environment you are implementing PHP into. For example in an enterprise environment there might already be an established standard where all event logs are monitored and reported to a central location. In this case it would be better to use the Syslog option so you know php events are being reported correctly.
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster
Still cannot get it to work
WOW, there have been 292,000+ reads on this thread.
Now I still have a problem. I have read every comment and read the instructions 6 times. I have been jacking with this thing for over 6 hours and my eyes are starting to cross. I have also read the "prompt to download..." post and I am still getting the prompt.
The application settings seem correct. I did it manually through IIS and I also ran the script. the mime type is right. i have tested my info.php file in both Firefox and IE and they both get the prompt.
I have inherited this system from the previous IT guy so i am not sure of the original setup, but I am pretty sure I have all the old PHP stuff out. I cannot find any php files on the system before I unzipped version 5.2.9 and I also unzipped the pecl-5.2.6-nts files. I have my subfolders done correctly, my path is right, the php file is modified correctly, but I just cannot find the answer to make the php display right.
The rest of my hair is falling out trying to find the fix. It is loaded up on an old Win2K box, but I would think it would still work. I have tired changing the app setting from the isapi.dll to the cgi.exe and neither one worked.
Any help you can give me would be graciously accepted.
Trick is to think like IIS
I used PHP on IIS 5 for a years, so that is not going to be the issue. Trick here will be to try and think a bit like IIS in terms of what settings dictate how files are handled.
1. Mime type dictate how files of a particular extension are handled. By default IIS does not have a mime type set for php, so if one has been added incorrectly then it could prevent php from working correctly. At the command prompt in your IIS adminscripts directory type in this command to see all your server mime types.
adsutil.vbs ENUM MimeMapif there is one for .php in there, I suggest you delete it. Have a read of this article on working with IIS mime types for more information.
2. If there is any server side processing required, then IIS will need a scriptmap (or filter) configured to tell IIS how to handle that particular file type. These settings have to be spot on, so paths have to be correct and you can't use spaces. Another point of confusion with scriptmaps is the inheritance hierarchy. Have a read of this article on working with IIS 6 scriptmaps inheritance for more information (content still applies to IIS 5).
3. Finally there is PHP and the PHP script itself. Things like an incorrect mime type setting in php.ini, or use of short tags in the php script can cause issues when IIS tries to execute the script. This information and more is contained in the article on trouble shooting the prompt to download php file which you've already read.
The answer to your issue will likely sit somewhere between point 1 and 3, however finding out exactly where the issue(s) are will require some investigation from your side. One potential cause could also be permissions, but see how you go with the above first.
----------------
Dominic Ryan
5 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster
Thanks!
Sorry Brashkquido,
I had issue with phpMyAdmin, so I uninstalled everything and try to begin at the beginning. Firstly, I tried to install PHP 5.2.9 on IIS6 (Windows Server 2003). I followed each step carefully (except downloading and using the PECL package, 'cause at the first time I can't find out which file to download). But at the last step, testing with the php file, it didn't work. So, I have to try another solution: http://shabbir.hassanally.net/blog/2007/10/16/howto-installing-mysql-php-and-phpmyadmin-on-iis-part-3-php/
You can see that he mentioned about some steps that you didn't. For example: in PATH variable, he said: "Add C:\PHP524 to THE BEGINNING of the string", and explained clearly the reason why. And after following his HOWTO, I could finally access the phpinfo.php :)
I'm really a newbie in PHP world. Tell me what you think about Shabbir's HOWTO.
Thanks again.