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.

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"

• 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.

If you get "the specified CGI application misbehaved" then you must use php5isapi.dll INSTEAD OF php.exe %s %S.

Spent couple of hours but fixed it. Please amend you article, if applicable.

Nice work, glad you got it

Nice work, glad you got it working. However, it is possible to get phpMyAdmin working with PHP CGI. If you are using PHP CGI and receive error messages such as you've described then it is likely that the CGI related directives in php.ini needed tweaking for Windows/IIS. Out of interest, what instructions did you follow that advised to use "php.exe %s %S"? If you were using PHP5, the PHP CGI executable is php-cgi.exe .

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

Thanks

Thanks, your tutorial above is kick ass.. do you have tutorial step by step similar like above, but this one to install MySQL on IIS 5.1 to work with PHP 5.

Thank you before and I really appreciate it.

Glad the tutorial was of some help. You can find a tutorial on how to install and configure MySQL 5 on Windows in the How To Guides section.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

500 is an internal server
Brashquido | Tue, 2007-11-20 14:31

Well i have no spaces put in the filenames or in the link

Added php to the path variable and also "phprc" too

Pecl extension i hav only mysql one enabled. Have done it according to the instruction you gave above and was working fine with all php pages until i restarted the system. After that am getting http 500 error. Dont knw y it is coming nw.

pls help

Was this your first attempt at installing PHP? Have you changed anything on your system since your last reboot? Are there any events in the event log that might shed some light
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

as you said i have disabled the friendly http error and then i got this message "%1 is not a valid Win32 application. " will that help you to trobleshoot.

What exactly have you set

What exactly have you set for your PHP application mapping? With PHP5 your application mapping should be either;
For CGI
X:\path\to\php\php-cgi.exe

For ISAPI
X:\path\to\php\php5isapi.dll

The only other way to map PHP for IIS is using FastCGI, but in most cases you'll be using one of the two above. If you have anything other than exactly what I've listed above (change the path to suite your environment) then PHP will not work.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

C:\path\to\php\php5isapi.dll

Have Done it according to the instructions given above in your list...and have set up the php5isapi.dll
in Home directory -> configuration.... but no web extension is done as mine is iis 5.

I'm running out of ideas.

I'm running out of ideas. The "%1 is not a valid Win32 application." error you are getting indicates several possibilities;

1) There are spaces in the application mapping path.

2) The application mapping extension is different from the actual scripts you are trying to run.E.g, the application mapping is .php3 and the actual scripts are .php.

3) The path to the actual php5isapi is wrong in your application mapping.

Apart from those I'm actually not too sure what else it could be off the top of my head. One question; as your using IIS 5, are you using URLScan or IIS Lockdown at all? If so, is PHP blocked in there at all?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster