IIS Tutorial Series (Part 1): Installing FastCGI and PHP for IIS 6.0

February 18th, 2010 | Tags: , ,

Note: This article is Part 1 of the IIS Tutorial Series.

Despite IIS 7.5 being the current stable IIS release, it is only available for servers running Windows Server 2008. However for the many of us who are still running Windows Server 2003 or Windows XP, IIS 6.0 is our only option. And many of us are still limited to that option.

In this tutorial I will be doing a walkthrough on installing FastCGI and PHP. For those who are a bit new to PHP on IIS, here’s a general view of what happens when a PHP page is call through the client’s web browser:
When the client requests a PHP resource (.php), IIS responds by calling FastCGI. FastCGI is the interface to CGI Programs (in this case, PHP), so the web server can focus on web page requests. FastCGI is then responsible for calling the PHP executable to execute the PHP script, and return its response back to IIS. IIS then returns that response back to the client.

Installing FastCGI
With the stable release of PHP 5.3 out for a while now, the only way to install PHP 5.3 on IIS is through a CGI Handler. PHP 5.2 and earlier allowed us to run PHP using ISAPI, but that option has been deprecated. For those of us intending to move forward, we would have to use CGI from now on.  We’ll go over installing the FastCGI handler on IIS 6.0.

You can download FastCGI for IIS 6.0 here (version 1.5 as of this time).

Run the executable on the web server to install FastCGI. You may have to restart your machine for the installation to complete. When that’s done, open up IIS Manager and view the list of Web Service Extensions on the server tree. There should be a “FastCGI Handler” extension in the list. Make sure its status is set to Allowed. And that’s it. FastCGI is installed!

Installing PHP
Download the latest version of PHP for Windows here.
We’ll be doing the manual method of installation, so download the ZIP version and which is Non Thread Safe. It’s completely up to you whether you want to use the PHP 5.2 series or the PHP 5.3 series. Some applications may work on PHP 5.2 but not 5.3. Either one, the installation process is the same.

Unzip the content to somewhere on your server. I prefer the base of the C drive: C:\php\
Rename the “php.ini-recommended” file to “php.ini” and make any adjustments to that configuration file. (I won’t go over that in this tutorial.) You can do this at a later time if you wish. Just like that, PHP is technically “installed” on your server.

Making PHP work
Now, it’s time to make IIS understand what to do with requests that have the .php extension. When IIS hear a .php file called, we want it to let FastCGI know, so FastCGI can call PHP. To do so, we’ll have to set up the extension mapping for .php. Open up IIS Manager again and navigate to “Web Sites”. Right-click on it and select “Properties”. Select the “Home Directory” tab, and within it, select “Configuration…” A new window pops up with a listing of Application Extensions.

Look for the .php extension and “Edit…” it. If it doesn’t exist, “Add…” the extension. A new windows pops up. For Executable, look for the FastCGI library. For most default installs, it should be under: C:\WINDOWS\system32\inetsrv\fcgiext.dll
For Verbs, limit it to: GET,POST,HEAD
Save all options.

IIS can request the FastCGI Executable when a .php resource is requested. Now, it’s time for FastCGI to talk to PHP by modifying FastCGI’s configuration file. For default installs, the config file should be located at: C:\WINDOWS\system32\inetsrv\fcgiext.ini
Open it in a text editor and add the following at the bottom:

[Types]
php=PHP

[PHP]
ExePath=c:\php\php-cgi.exe

The Types is the extensions it’s listening to and the corresponding configuration it will use. So here a “php” extention will use the [PHP] configuration. The [PHP] configuration has the path to PHP’s CGI executable. This is how FastCGI knows where to find PHP. Modify the path to where PHP is located on your server.
There are more options you can add, but this should get you going.

Testing the Installation
Test that the installation went successfully. Restart IIS and create a website hosting a PHP file and output phpinfo(). If everything went well, you should see the PHP Info page with hints of FastCGI being used in there.

Note: When I was doing this, I’ve also experienced a FastCGI error during this last step stating that “Access is denied”. I’m not sure if this is common, but I was able to fix the issue by adjusting the security permissions on the PHP installation folder. I make sure that the users: Administrators, NETWORK SERVICE and SYSTEM are listed. If not, add them, restart IIS, and try to load the PHP page again.

  1. Nick
    June 7th, 2010 at 05:52
    Reply | Quote | #1

    I spent 2 full days with other tutorials trying to get this to work, and then I found yours (nobody else mentioned the FastCGI requirement). Thanks for helping me finally get it!

  2. June 7th, 2010 at 19:37
    Reply | Quote | #2

    No problem! Glad it did help somebody. It was a real pain in the butt for me too.

  3. Patrick
    June 22nd, 2010 at 07:32
    Reply | Quote | #3

    Exact same situation! Thanks for the tutorial!

  4. June 23rd, 2010 at 20:19
    Reply | Quote | #4

    You’re welcome, Patrick!

  5. Sunil
    August 15th, 2010 at 10:53
    Reply | Quote | #5

    Great Tutorial Jimmy! Keep posting you tutorial series it has been very helpful.

  6. August 15th, 2010 at 13:09
    Reply | Quote | #6

    Sunil,

    Thanks for your feedback!

  7. Julie
    August 27th, 2010 at 06:15
    Reply | Quote | #7

    Thanks so much Jimmy! Out of all the information online, yours was simple and WORKED!

  8. August 27th, 2010 at 08:36
    Reply | Quote | #8

    Julie,

    Thanks for your wonderful comment. I’m glad that it was simple to understand!