IIS FastCGI and PHP: What you absolutely need to know to host PHP applications on IIS 6 and IIS 7

*************************
UPDATE: NOV 12, 2007: FastCGI RTM for IIS 6.0 / Windows Server 2003 is released on download center.
*************************

Everybody knows that IIS FastCGI is a great way to run PHP applications on IIS.

So, if you are looking to give FastCGI a try, where should you start?

The good news is that we've been making great strides at delivering a solid production experience for hosting PHP on IIS, for both IIS7 on Windows Vista/Windows Server 2008 and IIS6 / IIS5.1 on Windows Server 2003 and Windows XP.  This means that with high likelihood you can take advantage of this right away, even if you do not have access to the latest and greatest IIS7 build.

With all the coverage this work has been receiving, its starting to get out of hand.  Here is the information you absolutely need to know to get started:

If you run Windows Server 2003:

            Download the FastCGI RTM (released 11/12/2007)

            Docs at: www.iis.net/fastcgi

            My earlier blog post: FastCGI for IIS 6.0 is released on Download Center

If you run Windows XP:

            While the FastCGI RTM will work on Windows XP, it is not officially supported due to Microsoft software lifecycle policies.  I am bummed about it, but nothing we can do.  

            However, you should still be able to download and use it for development and testing on your XP machine (until you upgrade to Vista SP1).

If you run Vista:

            Download the FastCGI Techical Preview 2 release (released 1/31/2007).
            Starting with Vista SP1, and Windows Server 2008, FastCGI is no longer an out of band
            download, and is instead included with IIS7.  There will be no more out of band FastCGI updates
            for Vista.
            
            My earlier blog post: Turbo-charge your PHP applications with IIS FastCGI Technical Preview 2

            DOC: Installing PHP with the FastCGI technical preview.

If you run Vista SP1 beta or later:
AND
If you run Windows Server 20058 BETA3, RC0, or later:

            FastCGI is built-in!
 
            My earlier blog post: The latest on the FastCGI project and PHP support on IIS

            DOC: Using FastCGI to host PHP applications on IIS7.

You also should download and try the latest PHP build available from www.php.net/downloads. Starting with PHP 5.2.1, Zend has worked together with us to significantly improve the performance of the PHP engine itself on Windows, in addition to the platform improvements provided by FastCGI.  The current build is 5.2.4. 

Be sure to download a non-thread-safe build flavor for use with FastCGI, as this will give you a significant boost over thread-safe builds needed for the PHP ISAPI.

Hopefully this helps make sense of what's available, and gets you on your way.  Be sure to come back to the blog for more PHP/FastCGI news/info.

Thanks,

Mike

31 Comments

  1. Mike Volodarsky

    Yes, I’d say a lot of people know 🙂 There has been a great deal of talk and excitement around this, but this post is really about the straight facts to help people get started.

  2. Mike Volodarsky

    Hi John,

    The main reason why ISAPI is not an adequate solution is the lack of thread safety in many popular PHP extensions. The PHP core itself is thread safe, and so are some of the extensions, so its possible that some applications will work correctly in the ISAPI environment. However, many production environments do experience instability with the ISAPI. You can read more about this in my original post: http://mvolo.com/blogs/serverside/archive/2006/09/29/Making-PHP-rock-on-Windows_2F00_IIS.aspx.

    Thanks,

    Mike

  3. Anonymous

    I found out about this my just searching through the 2003 Updates Database. I was really surprised to see this option for IIS, now I can work more efficiently instead of having to run Linux or Apache! This is really cool. Great way to mix up scripting and application on one server instead of many.

  4. Anonymous

    Some 6 months ago I tried FastCGI in Vista 64-bit. It was quite painful; I think I ultimately got it to work… or almost to work, but I wouldn’t want to try it again. Is PHP / FastCGI is as mature as x86 version?

  5. Anonymous

    Several PHP Apps required Apache “mod_rewrite”.
    We can read about several PHP Apps at http://www.iis.net/phpapps, but not a word about this requirement.
    I read about some 3rd solutions like “IIS Mod-Rewrite Pro” that we have to buy.
    There is a Microsoft Solution?
    I don’t want to use in our Production Server a 3rd solution but how can we use Fastcgi/PHP5 with some real Apps like DRUPAL without “mode_rewrite”?

  6. Mike Volodarsky

    You dont need to do that, although, it is recommended – it can help avoid creating confusing handler mapping configuration where you may be accidentally using Isapi instead of FastCGI and visa versa.

    FastCGI is a more reliable way to host PHP applications so you should theoretically never install the ISAPI. If you follow the installation instructions in one of the linked articles, it will walk you through installing PHP with FastCGI without using the PHP Windows installer which may generate ISAPI configuration.

    Thanks,

    Mike

  7. Anonymous

    Mr  Program Manager  you have so many errors in links and text that I doubt IIS7 will work under your "management" Server 2006 what that means dude?

  8. Anonymous

    I just installed Vista SP1. I want to enable PHP, using the instructions on IIS.net. The instuctions say that FastCGI is included in SP1.
    When I go into IIS manager and click “Handler Mappings”, then click “add module mapping” (which is in the instructions), the dropdown list of modules does not contain an entry for fastCGI.
    I have rebooted a couple of times, and Vista says that its version is SP1, but I don’t see the fastcgi module.
    Am I doing something wrong?

  9. Mike Volodarsky

    Hi mumu,

    Thanks for spotting the “Windows Server 2006” typo, I fixed it. All other links are working – what other errors did you see?

    As far as your other concern, IIS 7.0 is “working” pretty well so far, be sure to try it 🙂

    Thanks,

    Mike

  10. Anonymous

    Thanks for the efforts to get PHP and IIS7 to be good neighbors; I am trying to get PHP 5.2.3 ro work on IIS7 I still have an issue getting PHP to work on my Vista Business installation – using the fastCGI or the IIS-ISAPI modules as suggested by bill’s blog on IIS.net. From localhost i call mytest.php, – then the page just hangs… – and no IIS error apge or HTTP40X.X error returns any suggestions?

  11. Mike Volodarsky

    Coolhand,

    Can you get a simple hello world php script working, or does it also hang?

    Be sure that you are creating the FastCGI mapping to php-cgi.exe, not php.exe. If you configure a random process that doesnt support FastCGI to be used with FastCGI, it may exibit hanging.

    If it doesnt help, post on forums.asp.net and we’ll help you more.

    Thanks,

    Mike

  12. Anonymous

    i have 2k3 and iis6, main site works fine however a ‘cname’ site does not. no matter whici one i use all i get is the phpinfo page displayed. and i have other url info chosen ie index.php or install.php, same thing.
    perhaps i have done something wrong?

  13. Anonymous

    i have 2k3 and iis6, main site works fine however a ‘cname’ site does not. no matter whici one i use all i get is the phpinfo page displayed. and i have other url info chosen ie index.php or install.php, same thing.
    perhaps i have done something wrong?

  14. Anonymous

    Please could someone address the issue that John Wielki queried above? People keep saying that fastCGI comes in II7 – and yet neither I nor four other people who I know have tried it have been able to discover the module through IIS manager.

    I did see – and try out – a command line workaround on one of the many threads I’ve been searching which made the fastCGI ‘discoverable’ – but putting files to testing server returned an ‘erroneous module’ fault which subsequently screwed up my ability to install/uninstall IIS components. I had to do a system restore.

    I am yet to hear of ANYBODY who has managed successfully to use IIS7 as a testing server for PHP web testing. I and one other have had to keep an XP machine running with IIS6 – because it works, – simply and efficiently!

  15. Mike Volodarsky

    NeilH,

    FastCGI is built-in in Windows Server 2008 and Windows Vista SP1, and requires to install the “CGI” component.

    Please see for detailed instructions: http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/.

    http://www.iis.net will have plenty of resources, and a dedicated forum for hosting PHP on IIS 7.0.

    Quite a few hosts are offering IIS7-based PHP … not sure how you missed it while searching.

    I do have to update this post with the latest links/info, sorry if it misled you in any way. Hope this helps –

    Mike

  16. Anonymous

    One side effect with the ‘not thread-safe’ PHP on IIS 7 with fastcgi is that the windows binaries for DBG or XDebug that are readily available work with the ‘thread-safe’ PHP. So if you dont have time to build your own, and who does, and you want to use a product like VS.PHP (Visual Studio 2008 IDE for PHP) for debugging, then reconsider the ‘not thread-safe’ PHP.

  17. Anonymous

    Vista sp1.
    For some reason the application keeps demanding isapi. I have changed the mappings handler to “FastCGI”.
    Handler “PHP” has a bad module “IsapiModule” in its module list

  18. Anonymous

    How can we print the php errors in IIS 7.0 on Windows 2008 server 64 bit version using FastCGI? From my experience when an error occurs e.g. mssql_conncet not defined in line 3 an Internal Server Error 500 is shown to the page. In php.ini errors are enabled of course!

  19. Anonymous

    Server 2008 r2 – IIS 7.5 & PHP 5.3.1 fastCGI.
    I know my stuff when it comes to working with PHP & IIS or so i thought when i tried to migrate an existing PHP with mysql db application that was working perfectly fine in IIS 6. 3 days of grief.
    mysterious error 500 page with no details. even with error logging & new error tracing, not much help out there when you search the error messages to actual fix it. even the error xml files that are created can not be opened in ie.
    fastcgi works great to display a php info screen, but thats all it can do.

  20. Anonymous

    Hi,
    I’ve a problem with php and virtual directory.
    phpinfo() report Virtual Directory support DISABLE.
    Php was installed by official Microsoft php.iis.net site.
    How do I enable the option?
    The site is in C: inetpubwwwrootsite
    The virtual directory is called Documents and physically is in E:Documents.
    Thanks

    Daniele

  21. Anonymous

    Note that I also had the “FastCGI not in module list” problem. Going to Add/Remove Windows Features dialog and *uninstalling* CGI (under IIS/WWW-Services/App-Dev-Features), waiting (an age) and then *reinstalling* CGI (and waiting another age) and lo!, I had FastCGI listed.

Leave a Reply to Mike Volodarsky Cancel reply

Your email address will not be published. Required fields are marked *