Introduction
This article explains how to setup and use the Microsoft IIS FastCGI technical preview to set up and run PHP applications on Windows Vista. Note that this article is not applicable to Windows Vista SP1 or Windows Server 2008, because those operating systems have FastCGI support already included in IIS7.
What is FastCGI?
FastCGI is a standard protocol that allows application frameworks' CGI executables to interface with the web server. The main difference from the standard CGI protocol is that FastCGI re-uses CGI processes for multiple requests, which provides a significant performance boost as compared to CGI.
The IIS FastCGI support enables IIS to host normal CGI programs like PHP, or Ruby On Rails, using the FastCGI protocol, offering high-performance and stability for production deployment of such application frameworks (NOTE: the tech preview is for evaluation purposes only and should not be used in production).
Using the IIS FastCGI support involves the following 3 pieces:
- The IIS web server (FastCGI support is provided for IIS6 and IIS7).
- The IIS FastCGI component.
- The CGI program being hosted.
The web server dispatches http requests to your application to the FastCGI component, which in turn launches the CGI program executable, and forwards the request for processing. Once the request is finished and the response is returned back to the server and sent to the client, the CGI process is re-used for a subsequent request. This allows to avoid the high performance penalty of starting a new process for each request, which results in MUCH better performance and scalability in a production environment.
If you want to learn more about the FastCGI protocol, read more at http://www.fastcgi.com/devkit/doc/fcgi-spec.html.
Obtaining the Technical Preview
Download the FastCGI Technical Preview for IIS 7 on Windows Vista - here. If you are using Windows Vista SP1 or Windows Server 2008 then you do not need to install any additional components as FastCGI is included in IIS7 on those operating systems. To configure FastCGI and PHP on Windows Vista SP1 or Windows Server 2008 follow the instructions described here.
The FastCGI support is fully compatible with the current official PHP distribution for Windows available from www.php.net/downloads.
Installing PHP on IIS using FastCGI support
To install the FastCGI tech preview, follow the steps below:
- Download the FastCGI tech preview component for your IIS version (See Obtaining the tech preview on the previous page).
- Unzip the package to a local directory.
- Open a command line window, change to the directory where you unzipped the FastCGI tech preview files, and run the installer:
> fcgisetup.exe /install
Figure 1: IIS 7.0 FastCGI Installation.
Install and configure PHP
The FastCGI support is fully compatible with the current official PHP 4.4.x and PHP 5.x distribution for Windows available from www.php.net/downloads. Since FastCGI hosts and executes php processes in a single threaded manner, it is recommended that you download and install non-thread-safe PHP build available for Windows. The non-thread-safe PHP build provides a major performance boost caused by lack of thread safety that is acceptable for a single-concurrency environment like FastCGI.
You can also use the FastCGI with your existing PHP 4.4.x or PHP 5.x installations. Note that PHP distributions starting from PHP 5.2.1 will contain the performance enhancements developed by Zend to improve the performance of the PHP engine on Windows. These latest versions will provide the optimal PHP performance on the IIS/FastCGI platform.
To install PHP follow these steps:
- Download non-thread safe build of PHP from here: http://www.php.net/downloads.php
- Unpack the PHP files to C:\PHP (or other directory of your choice)
- In the folder, where you unpacked PHP files, copy php.ini-recommended to php.ini <Issue: should "php.ini-dist" instead of "php.ini" ? >
Configure FastCGI to work with PHP
You must be running as Administrator to configure FastCGI. To do this, click the Start menu, expand Programs, find the "Command Prompt" icon, right click, and chose "Run as Administrator". Use the following command to register PHP with FastCGI:
> fcgisetup.exe /add C:\PHP\php-cgi.exe PHP
Figure 2: Register PHP with IIS 7.0 FastCGI.
You can add additional CGI programs later using the /add switch, specifying a comma separated list of extensions to map them to. For more information about the commands supported by the installer, use the /? switch.
You can uninstall FastCGI support by using the /uninstall switch. If you are using the IIS 5.x / IIS 6.0 version of FastCGI, you will also want to use the /r switch when uninstalling to remove the FastCGI scriptmaps from the entire server if you also used the /r switch to register CGI programs.
Using the FastCGI Technical Preview
After installing the FastCGI support, and registering the PHP CGI, you should be able to request your PHP application and use it normally.
To test that things are working, create and request a phpinfo.php page in your site that contains the following:
<?php
phpinfo();
?>
You should see something like:
Figure 3: Request phpinfo.php to confirm PHP is working via IIS FastCGI.
Note that the Server API indicates that PHP is hosted in FastCGI mode. You may need to edit the specified PHP.INI file to configure PHP appropriately for your application as you do normally.
Getting more information
To discuss the FastCGI Support for IIS, or file bug reports, please use the FastCGI forums:
- IIS 5.x / IIS 6 FastCGI forum;
- IIS7 FastCGI forum
To see a list of known issues with FastCGI in IIS, see known issues.
To get more information regarding running various PHP applications on IIS refer to
PHP on IIS portal
PHP community forum