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

failed to open stream: No such file or directory in

Hi, i followed your guide and I installed fine (good guide), I can see the phpinfo.
but when i run my proyect i recieved

Warning: include(ayto_gestion/SqlFun.php) [function.include]: failed to open stream: No such file or directory in C:\Archivos de programa\PHP Designer 2005\webs\ayto_gestion\login.php on line 36

Warning: include() [function.include]: Failed opening 'ayto_gestion/SqlFun.php' for inclusion (include_path='.;C:\php5\pear:/docroot') in C:\Archivos de programa\PHP Designer 2005\webs\ayto_gestion\login.php on line 36

Fatal error: Class 'SqlFun' not found in C:\Archivos de programa\PHP Designer 2005\webs\ayto_gestion\login.php on line 37

Obviously i put these files in this direction, but i suppose i have to change anything in the php.ini could you help me?

Brashquido's picture

Glad the guide helped! First

Glad the guide helped! First thing to check will be your NTFS permissions. Ensure you IUSR account has read permissions to all your application directories and files. Using the incude() function will also mean you will need to add the directories which contain the files referenced by your include statement to the "include_path" directive in php.ini.
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Hi again;

I set my route in include_pat (C:\Archivos de programa\PHP Designer 2005\webs), and I'm sure that i have permission because i use administrator, but i recieve the same.
I have read that i have to change doc_root and set the path, but it doesn´t work. You can see that it is a page for login, and after this I try to connect to mysql, could it be a problem?
sorry I'm very lost with it.

thank a lot.

Brashquido's picture

You have spaces in your

You have spaces in your path. Did you ensure you enclosed the path with ""? Sp the include_path would look something like;

include_path = "C:\Archivos de programa\PHP Designer 2005\webs"

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

Anonymous's picture

thanks

thanks for your help...
It was bizarre, because I was using php 4, and when i upgrade to 5, the path sttoped working, so i added a "/", it started working again.
bye and good work

Anonymous's picture

First ,thanks for your tutorial,but for connecting to mysql ?

Hi,
Thanks for your help.
I used your guides and i can see information of phpinfo() function in my browser ,but when i want connect to mysql i receive this error :
Fatal error: Call to undefined function mysql_connect()
is there any help?
Thanks
Jamshid

Brashquido's picture

Is the MySQL extension loaded?

When using the phpinfo() function is the MySQL extension loaded?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

PHP IIS W2003 HTTP 500 Internal Server Error on subdirectories

I am getting the
HTTP 500 Internal Server Error
on tested working php scripts
in sub directories only !

They work fine in the root of the website.

PHP Version 5.2.5
Windows 2003 server
IIS

Permissions are the same in the sub directories.

Any ideas?

Cheers
Alex

Anonymous's picture

the page cannot be displayed

Hi,
After I carefully follow your instructions, still the page cannot be displayed. Im running at win xp, iis 5.1 with asp.net 2.0 installed. I try to install PHP 5.2.5

HTTP 403.1 Forbidden: Execute Access Forbidden
Internet Information Services

--------------------------------------------------------------------------------

You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.

Need your help. Thanks!

Mark

Brashquido's picture

PHP HTTP 500 error

Hi Alex,

Have you had a look through the article I wrote on troubleshooting the PHP HTTP 500 error?

Mark,

Can you look at the "home directory" tab in your IIS admin manager and let me know what your execute permission is set to?
----------------
Dominic Ryan
3 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster