How to install PHP on IIS

Posted: Sep 19, 2006  48 comments  

Average Rating

Tags
Administrators
Developers
IIS News Item
IIS7
PHP
Samples & Demos

Share this Post

*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

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

Sep 21 2006 by John C. Bland II on *

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??

Sep 26 2006 by Xeno

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-

Sep 27 2006 by bills

The pictures are not showing, which makes step 8 very hard to complete :-(

Sep 27 2006 by Lars

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.

Sep 27 2006 by bills

The pictures are not showing. =(

Sep 28 2006 by 440hz

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

Sep 28 2006 by bills

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

Sep 29 2006 by bills

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.

Oct 05 2006 by Chris McGrath

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

Oct 05 2006 by bills

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

Oct 08 2006 by Simon

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????

Oct 10 2006 by John Wikman

Chris, I expect that to be a permissions issue. Check folder permissions on the folder "sessiondata" and "uploadtemp" in your PHP installation.

Oct 10 2006 by Maarten

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

Oct 11 2006 by John Wikman

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.

Oct 11 2006 by bills

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

Oct 18 2006 by bills

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

Nov 06 2006 by Technology Articles

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.

Nov 09 2006 by DK

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.

Nov 09 2006 by bills

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

Nov 24 2006 by hirsuwano's Blog

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

Dec 18 2006 by Daniel

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

Jan 07 2007 by Fredy

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

Jan 19 2007 by cnblogs.com

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

Jan 19 2007 by Ring

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

Feb 06 2007 by All About Interop

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

May 03 2007 by Alles over Hosting en Software + Services

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

Nov 10 2007 by tips on how to blog » How To Blog -

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

Nov 29 2007 by tips on how to blog » How To Blog -

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

Dec 10 2007 by Hosting en Software + Services

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

Jan 22 2008 by luka.manojlovic.net » Blog Archive » Installing PHP on IIS7.0 on Windows server 2008

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

Apr 01 2008 by PHP on IIS 7 - Dave’s Blog

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

Jun 01 2008 by ??pu??lar??m » Blog Archive » IIS7 Access Database Baglanti Sorunu

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

Jun 26 2008 by Steve Huff's Blog

Pingback from  quick question regarding c and php. - TalkPHP

Jul 10 2008 by quick question regarding c and php. - TalkPHP

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

Oct 24 2008 by How to install PHP on IIS « Xinyustudio

Andere haben Werbebanner in gratis Web Spaces vorgesehen.

Nov 27 2008 by Kostenloser WEB Space

Pingback from  Como Instalar PHP sobre IIS7 at Guerratopia

Dec 01 2008 by Como Instalar PHP sobre IIS7 at Guerratopia

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

Dec 16 2008 by blogring.org

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

Jan 18 2009 by Makeing exstentions work on vista ultimate ASP or PHP (MIME extensions issue) | keyongtech

Pingback from  Vista Ultimate IIS und PHP | hilpers

Jan 20 2009 by Vista Ultimate IIS und PHP | hilpers

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

Jan 28 2009 by IIS 7, PHP y SQL Server 2005 en Windows 2008 | WebLatam

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

Feb 11 2009 by 2K8 - IIS7 und PHP - MCSEboard.de MCSE Forum

Pingback from  Keyboard Face &raquo; Installing PHP on IIS

Mar 17 2009 by Keyboard Face » Installing PHP on IIS