How to install PHP on IIS

Posted: Sep 19, 2006  45 comments  

Average Rating

Tags
Administrators
Developers
IIS News Item
IIS7
PHP
Samples & Demos

*Updated Recommendations - Please read the following instructions for running PHP fast and reliably*

The FASTEST and EASIEST way to install PHP on IIS is using Microsoft’s Web Platform installer.  It completely automates setting up IIS, FastCGI and the latest version of PHP from the php.net site.  To install it, just click this button:

wpiBadgeGreen

If you don’t have Web PI v2 installed, you will be prompted to install it.  Once installed, the tool will launch.  You can either navigate to the “Web Platform” tab and select “PHP” under “Framework and Runtimes” customize link, or close your browser, re-open to this blog and click the button again to launch the tool directly into PHP install.

 

For step-by-step instructions on how to install PHP on IIS6 (Windows 2003) with the new Microsoft FastCGI module, see Configuring FastCGI Extension for IIS 6.0.

For step-by-step instructions on how to install PHP on IIS7 (Windows Vista SP1 and Windows 2008) see, Using FastCGI to Host PHP Applications on IIS 7.0

 

My original blog post follows below and provides instructions for how to install IIS7 on Vista (RTM) using the ISAPI-based PHP.  I strongly recommend you upgrade to Vista SP1, however, and use the Using FastCGI to Host PHP Applications on IIS 7.0 instead. 

 

Here is a step-by-step guide for Vista RTM:

1) Download PHP from http://www.php.net/downloads.php.  I get the zip package because I think it is just as easy, and gives me control over setup.

2) Unzip the php...zip file to your drive.  I usually unzip it to C:\php

3) Copy the c:\php\php.ini-dist file to c:\windows\php.ini.  Tweak it as needed.

4) Install IIS7, making sure you install the ISAPI Extension component (for PHP-ISAPI - which is what I use) or the CGI component (if you prefer CGI) during IIS installation (ISAPI and CGI are *not* installed by default)

5) Open the IIS Manager (C:\windows\system32\inetsrv\inetmgr.exe

6) Click on "Handler Mappings"

(click here for full size image)

7) Click on the "Add Script Map" task on the right (in blue):

(click here for full size image)

8) Fill in the dialog box like this:

9) Pause to enjoy this handy dialog box that I had added late in RC1 just for you, then click "yes"

If you click "Yes" it will automatically register this ISAPI /CGI with the extension restriction list - the feature we added in IIS6 to prevent unauthorized executables from running on the server.  This saves time, and considering the fact that you're adding the scriptmap, it's a safe bet you want it to run. :)

10) go to your C:\inetpub\wwwroot directory and create a test.php page.  You can use the simple

<?php  phpinfo();  ?>

function to test if PHP is working correctly. 

 

Enjoy!

 

Adddendum: several people have commented below that they are having problems getting PHP sessions to work on IIS7/Vista.  Please see this post for more information on the issue.

Another note: PHP users may wish to try out the recently announced FastCGI support from Microsoft for improved reliability and performance.  See this post for more information on the announcement, and this post for a demo of the new feature.

Comments

  1. John C. Bland II on *
    September 21, 2006

    I&#8217;m in a session with Bill Staples titled &#8220;IIS on PHP&#8221; and he showed how to setup PHP to work with IIS 7. He has documented it on his blog here. I&#8217;ll just tell you real quick what to do....

  2. Xeno
    September 26, 2006
    But you are still running PHP as a CGI! Why PHP runs so well with Apache is because it acts as a module and stays up. In this instance, everytime you want to run a PHP app, you have to START PHP first which takes a half a second longer to execute your scripts. Also, IIS still only runs on Windows and I can't shut off the GUI; even from a command line, the Windowing functionality is still using resource that the web server could be using. With Apache on Linux, I can shut off the X-server (or not even install it at all) and have more resources dedicated to my web server. These for me are still the ongoing issues as to why I don't use PHP on IIS. Why use it on Windows with IIS when Apache on Linux gives so much better performance??
  3. bills
    September 27, 2006

    Xeno - actually, if you look more closely the configuration I do above is to run PHP as an ISAPI, which runs in-process with the IIS worker process.  This is essentially the same as running mod_php on apache.  The biggest difference is that ISAPI requires all of the PHP extensions to be threadsafe, since IIS worker processes are multi-threaded.  If this is an issue, then the CGI route is safer, since each request runs in it's own single-threaded process.

    In order to provide the best performance, and reliability of PHP on windows, I'd recommend using a fastCGI extension for IIS.  There are several of them out there, including one from Zend (http://www.zend.com/) which enables PHP to run quite fast on Windows.  This is a feature we intend to add to IIS in the coming year.  Hope this helps-

  4. Lars
    September 27, 2006
    The pictures are not showing, which makes step 8 very hard to complete :-(
  5. bills
    September 27, 2006

    Lars - hmm..I'm not sure why they didn't show up for you, they are looking fine right now.  Send me a message with a reply address, and I'll be happy to email instructions to you.

  6. 440hz
    September 28, 2006
    The pictures are not showing. =(
  7. bills
    September 28, 2006

    ugh, sorry guys.  due to a misconfiguration the images were not working for some folks.  this has been fixed

  8. bills
    September 29, 2006

    Maarten Balliauw has posted an alternative way to configure PHP on IIS using FastCGI which will avoid any threadsafety issues you may see with PHP extensions.  See his blog post here:  http://www.balliauw.be/maarten/blog/16,php-on-iis7-rc-1-but-unsafe.htm

  9. Chris McGrath
    October 5, 2006
    i just installed php 5 under iis7 and im getting permission denied errors whenever i try i store information in sessions any help with this would be appreciated.
  10. bills
    October 5, 2006

    Hey Chris - send me mail with more specifics on the error, and I'll see if I can help or at least point you in the right direction.  thanks

  11. Simon
    October 8, 2006
    I'm getting the same error as Chris it says: Warning: session_start() [function.session-start]: open(C:\Windows\SERVIC~2\NETWOR~1\AppData\Local\Temp\\sess_c74ed31a512f9111809d058373345415, O_RDWR) failed: Permission denied (13) in C:\inetpub\wwwroot\test.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\inetpub\wwwroot\test.php:7) in C:\inetpub\wwwroot\test.php on line 7 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\inetpub\wwwroot\test.php:7) in C:\inetpub\wwwroot\test.php on line 7 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506) Warning: get_browser() [function.get-browser]: browscap ini directive not set. in C:\inetpub\wwwroot\test.php on line 12
  12. John Wikman
    October 10, 2006
    Do you know if this method has any inherent issues with running sessions? I'm just learning php and am working on a very simple form project that uses a session to send info from one form to a confirmation page. I noticed that I got really funky errors when I started the files with , so I assume running php in this method already starts the session????
  13. Maarten
    October 10, 2006
    Chris, I expect that to be a permissions issue. Check folder permissions on the folder "sessiondata" and "uploadtemp" in your PHP installation.
  14. John Wikman
    October 11, 2006
    I've made the entire PHP directory fully open (writable by anyone) and am still getting that error. I don't have the sessiondata or uploadtemp folders in my php directory, though...??
  15. bills
    October 11, 2006

    Hi John - session data is stored in a temporary directory under the identity which the application is running as - by default NetworkService.  The error message you get should specify which directory PHP is having trouble writing session data to.  For example, in Simon's case above, the directory was:  C:\Windows\SERVIC~2\NETWOR~1\AppData\Local\Temp\  This is the directory that the web server needs write access to.  Also, if you could email me a test PHP script that reproduces this issue, I can try it here and give you more specifics on how to fix it.  I tried using start-session, and it worked for me without any problems, so I suspect there is something else specific to your app that is triggering the error.  you may also want to check out the documentation for session in PHP, located here:  http://us2.php.net/session  using the session.save_path variable in your php.ini, you should be able to reconfigure the path for session data to something more accessible.

  16. bills
    October 18, 2006

    See my latest blog post for more information on how to solve the session / temporary directory issues:  http://blogs.iis.net/bills/archive/2006/10/18/loadUserProfile-and-IIS7-_2D00_-understanding-temporary-directory-failures.aspx

  17. Technology Articles
    November 6, 2006

    Today, Microsoft and Zend announced a joint technical preview aimed at providing best-ever support for running PHP applications on IIS in a reliable, and hi-performance way. This article explains how to use the Microsoft IIS FastCGI technical preview

  18. DK
    November 9, 2006

    I spent a looong time trying to figure out why I couldn't get PHP 4.4.x working with IIS 7... and I never could. Switched to PHP 5, used the same configuration steps and it worked fine.

    In researching this topic, I never came across any warning about PHP 4.4.x - so maybe this will save someone the headache. Just use PHP 5.

  19. bills
    November 9, 2006

    DK - here are a few tips to get PHP4 to work using the same method described above.

    1) extract php-4.4.4-win32.zip to c:\php4 directory

    2) copy the php4isapi.dll from the c:\php4\sapi directory into c:\php4

    3) rename c:\php4\php.ini-dist to php.ini and copy it to c:\windows

    4) map *.php to the c:\php4\php4isapi.dll using the steps above (subtitute it for php5isapi.dll above)

    If you still have problems, try the PHP forum on forums.iis.net, and we'll help troubleshoot.

  20. hirsuwano's Blog
    November 24, 2006

    IIS7へのPHPのインストール方法が記述されています。http://blogs.iis.net/bills/archive/2006/09/19/How-to-install-PHP-on-IIS7-_2800_RC1_2900_.aspxIIS5、IIS6でのスクリプトマッピングの追加とほぼ同様な手順で行えます。Webサイト全体か特定のアプリケーションのみPHPのスクリプトマッピングを追加する ...

  21. Daniel
    December 18, 2006

    I setup PHP 5 to map to the file on IIS 7 and I am able to get the php pages loaded on my localhost. But I get a blank page, any ideas?

    Daniel

  22. Fredy
    January 7, 2007

    Hi Bill - i followed your instructions and php seems to work; however i can't get phpInfo() to display. All i get is a blank page...

    I'm running Vista RC2...

  23. cnblogs.com
    January 19, 2007

    IIS7伴随着Vista已经悄悄来临,学习的时候我也摘录了一些有关于此的文章。 不敢独享,还是贴出来大家共享吧! 初识IIS7 A Quick Look at IIS 7 这篇文章中浅显地介绍的IIS7的一些新特性,很容易就能对IIS7的特性有一个初略的了解。

  24. Ring
    January 19, 2007

    IIS7伴随着Vista已经悄悄来临,学习的时候我也摘录了一些有关于此的文章。不敢独享,还是贴出来大家共享吧!初识IIS7AQuickLookatIIS7这篇文章中浅显地介绍的IIS7的...

  25. All About Interop
    February 6, 2007

    I upgraded my work machine, back in October. My old standby IBM Thinkpad T30, after years of loyal service,

  26. Alles over Hosting en Software + Services
    May 3, 2007

    Hi All, This is once again a posting in English. Yesterday and today I must have spend over 3...

  27. tips on how to blog » How To Blog -
    November 10, 2007

    Pingback from  tips on how to blog &raquo; How To Blog -

  28. tips on how to blog » How To Blog -
    November 29, 2007

    Pingback from  tips on how to blog &raquo; How To Blog -

  29. Hosting en Software + Services
    December 10, 2007

    Hi All, This is once again a posting in English. Yesterday and today I must have spend over 3 hours figuring

  30. luka.manojlovic.net » Blog Archive » Installing PHP on IIS7.0 on Windows server 2008
    January 22, 2008

    Pingback from  luka.manojlovic.net  &raquo; Blog Archive   &raquo; Installing PHP on IIS7.0 on Windows server 2008

  31. http://blogs.iis.net/bills/archive/2006/09/19/How-to-install-PHP-on-IIS7-_2800_RC1_2900_.aspx
    March 17, 2008

    Pingback from  blogs.iis.net/.../How-to-install-PHP-on-IIS7-_2800_RC1_2900_.aspx

  32. PHP on IIS 7 - Dave’s Blog
    April 1, 2008

    Pingback from  PHP on IIS 7 - Dave&#8217;s Blog

  33. ??pu??lar??m » Blog Archive » IIS7 Access Database Baglanti Sorunu
    June 1, 2008

    Pingback from  ??pu??lar??m  &raquo; Blog Archive   &raquo; IIS7 Access Database Baglanti Sorunu

  34. Steve Huff's Blog
    June 26, 2008

    Getting PHP, MySQL, IIS, and Vista to Play Nicely

  35. quick question regarding c and php. - TalkPHP
    July 10, 2008

    Pingback from  quick question regarding c and php. - TalkPHP

  36. How to install PHP on IIS « Xinyustudio
    October 24, 2008

    Pingback from  How to install PHP on IIS &laquo; Xinyustudio

  37. Kostenloser WEB Space
    November 27, 2008

    Andere haben Werbebanner in gratis Web Spaces vorgesehen.

  38. Como Instalar PHP sobre IIS7 at Guerratopia
    December 1, 2008

    Pingback from  Como Instalar PHP sobre IIS7 at Guerratopia

  39. blogring.org
    December 16, 2008

    fastcgi+iisに関するブログをまとめています。

  40. Makeing exstentions work on vista ultimate ASP or PHP (MIME extensions issue) | keyongtech
    January 18, 2009

    Pingback from  Makeing exstentions work on vista ultimate ASP  or PHP (MIME extensions issue) | keyongtech

  41. Vista Ultimate IIS und PHP | hilpers
    January 20, 2009

    Pingback from  Vista Ultimate IIS und PHP | hilpers

  42. IIS 7, PHP y SQL Server 2005 en Windows 2008 | WebLatam
    January 28, 2009

    Pingback from  IIS 7, PHP y SQL Server 2005 en Windows 2008 | WebLatam

  43. 2K8 - IIS7 und PHP - MCSEboard.de MCSE Forum
    February 11, 2009

    Pingback from  2K8 - IIS7 und PHP - MCSEboard.de MCSE Forum

  44. Keyboard Face » Installing PHP on IIS
    March 17, 2009

    Pingback from  Keyboard Face &raquo; Installing PHP on IIS

  45. Setting up a testing server
    January 31, 2010

    Pingback from  Setting up a testing server