Introduction
On October 30th, 2006, Microsoft and Zend announced a joint technical preview aimed at providing the best support for running PHP applications on IIS in a reliable, and high-performance way. Today, the IIS team announces the Go Live release of the FastCGI extension for IIS 6.0, which addresses issues reported by the community for previous technical preview releases.
This article explains how to use the Microsoft IIS FastCGI extension to set up and run PHP applications on Windows XP and Windows Server® 2003 operating systems.
What is FastCGI?
FastCGI is a standard protocol that allows application frameworks' CGI executables to interface with the web server. It differs from the standard CGI protocol in 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 with the FastCGI protocol and offer high-performance and stability for production deployment of such application frameworks.
Using the IIS FastCGI support involves the following:
- The IIS web server (FastCGI Extension Go Live release supports IIS 6.0)
- The IIS FastCGI extension
- The CGI program (such as php-cgi.exe)
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 helps 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.
To learn more about the FastCGI protocol, see http://www.fastcgi.com/devkit/doc/fcgi-spec.html.
Installing the FastCGI Extension for IIS 6.0
The FastCGI extension for 32bit and 64bit Windows XP and Windows Server 2003 can be downloaded here:
http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1521
When you run FastCGI installer, it copies FastCGI specific files to "%WINDIR%\system32\inetsrv" folder and then registers and enables FastCGI Web Server Extension. Out of the files that the installer copies, be aware of the following:
- fcgiext.dll – This is the actual FastCGI handler that communicates with FastCGI enabled processes for processing requests
- fcgiext.ini – This is the configuration file that contains mapping of file extensions to FastCGI processes. It also contains the configuration of FastCGI process pools.
- fcgiconfig.js – This configures FastCGI extension. The script updates the fcgiext.ini file, modifies the IIS metabase and recycles the web service application pools if necessary.
Download and Install PHP
The FastCGI extension 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 the FastCGI extension hosts and executes php processes in a single threaded manner, it is recommended that you download and install the non-thread-safe PHP build available for Windows. The non-thread-safe PHP build provides a major performance boost from a lack of thread safety that is acceptable for a single-concurrency environment like FastCGI.
You can also use the FastCGI extension with existing PHP 4.4.x or PHP 5.x installations.
Note: PHP distributions starting from PHP 5.2.1 contain the performance enhancements developed by Zend to improve the performance of the PHP engine on Windows. These latest versions provide the optimal PHP performance on the IIS/FastCGI platform.
The Zend Core for Windows technical preview provides a preview of the commercial PHP product that contains the PHP performance improvements for Windows as well as additional improvements and features of the Zend Core product.
Configuring FastCGI Extension to Work with PHP
Once PHP is installed on Windows, you have two options for configuring FastCGI: use the configuration script provided with the installation of the FastCGI extension, or perform all the configuration tasks manually by modifying IIS configuration settings and fcgiext.ini file. Depending on the option, refer to the corresponding sections below.
Using Script for Configuring FastCGI Extension to Work with PHP
The configuration script with the name fcgconfig.js is provided with the installation of FastCGI extension and is located in %WINDIR%\system32\inetsrv. To configure FastCGI extension to work with PHP, follow the steps below:
Open a command line window, change the current directory to %WINDIR%\system32\inetsrv, and run the configuration script to register the PHP CGI program as the one that will be processing .php extensions:
cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"
(replace C:\PHP\php-cgi.exe with the path to php-cgi.exe if you installed to a directory other than C:\PHP)
Note: If you do not want to register the PHP extension to be processed by the FastCGI component on your entire server, and only want to register it for a specific web site, then add a "–site:[siteId]" argument, e.g:
cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe" –site:1
Note: For a complete list of configuration parameters supported by FastCGI extension, refer to the FastCGI extension documentation.
Manually Configuring FastCGI Extension to Work with PHP
To manually configure the IIS and FastCGI extension, you must create script mappings for the PHP extension in the IIS metabase and modify fcgiext.ini file located in %WINDIR%\system32\inetsrv.
Create script mapping
- Launch inetmgr.exe.
- Double click the machine icon for the local computer.
- Right click on "Web Sites" and pick "Properties."
- Click the "Home Directory" tab.
- Click the "Configuration…" button.
- Click the "Add…" button.
- Browse to the fcgiext.dll located in %WINDIR%\system32\inetsrv.
Note: If you need to use FastCGI in 32 bit mode on a 64 bit machine, then browse to %WINDIR%\SysWOW64\inetsrv.
8. Enter .php as the Extension.
9. Enter Verbs as GET,HEAD,POST .
10. Ensure that "Script Engine" and "Verify that file exists" are checked.
11. Click OK.
Modify fcigext.ini file
Once the script mapping is added, modify the fcgiext.ini file:
- Add an extension to application mapping (php=PHP) to the [Types] section.
- Add [PHP] section with ExePath=c:\php\php-cgi.exe (assuming you installed PHP files to C:\PHP folder).
[Types]
…
php=PHP
…
[PHP]
ExePath=c:\php\php-cgi.exe
After all the changes to fcgiext.ini the file are saved, restart the application pool associated with the web site that hosts your PHP applications.
Configure default document in IIS
Most of the PHP applications use a file named index.php as the default application document. Configure IIS to treat this file as the default content page:
- Launch inetmgr.exe.
- Double click the machine icon for the local computer.
- Right click "Web Sites" and pick "Properties."
- Click the "Documents" tab.
- Click the "Add…" button and enter "index.php" for "Default Document Name:"
- Click "OK."
Setting FastCGI Configuration for Optimal Functionality, Security and Performance with PHP
Full PHP functionality support and performance of PHP applications running on the FastCGI extension were the main goals and focus for the IIS team. During our internal testing and in collaboration with Zend Technologies, we identified the set of configuration settings for the FastCGI extension and PHP that provide optimal functionality and performance for PHP applications when running on Windows via the FastCGI extension.
Configure your server as described below:
1. Modify the php.ini file as follows:
- Set fastcgi.impersonate = 1. FastCGI under IIS supports the ability to impersonate the security tokens of the calling client. This allows IIS to define the security context under which the request runs.
- Set cgi.fix_pathinfo=1. cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behavior was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not care what PATH_INFO is. For more information on PATH_INFO, see the cgi specifications. Setting this to 1 causes PHP CGI to fix its paths to conform to the specification.
- Set cgi.force_redirect = 0.
2. Set the FastCGI configuration settings for the PHP section by running fcgiconfig.js as follows:
- Set the FastCGI process pool property InstanceMaxRequests to 10000. This setting specifies that the FastCGI extension will recycle php-cgi.exe after it has processed 10000 requests successfully.
> cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:10000
3. Configure the FastCGI extension to set PHP_FCGI_MAX_REQUESTS environment variables for the PHP process to 10000.This setting instructs php-cgi.exe to recycle itself after it has processed 10000 requests successfully.
> cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
Note: You can configure InstanceMaxRequests and PHP_FCGI_MAX_REQUESTS to use numbers other than 10000. As a general rule, always make sure that the value of InstanceMaxRequests is less than or equal to the value of PHP_FCGI_MAX_REQUESTS.
Testing PHP CGI
After installing the FastCGI extension, and registering and configuring the PHP CGI, you can request your PHP application and use it normally.
To test, create and request a phpinfo.php page in your site that contains the following:
<?php
phpinfo();
?>
You see something like:

Note that the Server API indicates that PHP is hosted in FastCGI mode.
Installing phpBB Application for Ase with FastCGI Extension
phpBB is a popular Open Source forum solution. It provides a large and very customizable set of features that include: powerful permissions systems, private messaging, search functions, a customizable template and language system and support for multiple databases. For more information about phpBB, see http://www.phpbb.com . For phpBB community specific information, see http://www.phpbb.com/community/.
This section goes through the steps required to install phpBB to work with the FastCGI extension on IIS 6.0.
The following steps assume that you have completed the setup and configuration of the FastCGI extension and PHP libraries as described in the previous sections.
Download and Unpack the Application
First, download the latest stable release of phpBB. For this article, we used phpBB 2.0.22 that is available here. Once you download the package, uncompress it and copy all the files and folders to C:\Inetpub\wwwroot\phpBB2.
Setup the Database
In order to use phpBB, you must have access to a database. For this walkthrough, we use MS SQL server 2005. You can also use MS SQL Server Express, MS Access, MySQL or others.
Before starting the install, create a database on the database server. Also create a database user and grant this user db ownership permission to the database. If you are using MS SQL Server 2005, then open Microsoft SQL Server Management Studio and click the "New Query" button. Enter the following script into the query window (this script creates the database and user necessary for the phpbb application).
USE [master]
GO
CREATE DATABASE phpbb2
GO
CREATE LOGIN [phpbb2]
WITH PASSWORD=N'phpbb2',
DEFAULT_DATABASE=[phpbb2],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
GO
USE [phpbb2]
GO
CREATE USER [phpbb2] FOR LOGIN [phpbb2] WITH DEFAULT_SCHEMA=[dbo]
Setup and Configure the Application
Open your web browser and browse to http://localhost/phpBB2/index.php. This redirects you to the phpBB setup page. Enter the required installation information as shown in the screen shot below (replace the Database Server Hostname with the name of your database server). Click "Start Install".
On the next page, phpBB asks you to choose a method for updating the config.php file. Choose "Just send the file and I'll FTP it manually". Save the file into the C:\Inetpub\wwwroot\phpBB2 folder.
Note: Change the access permissions on the config.php that you have just saved. If your web site is configured to allow anonymous users, then you mus grant the access permissions to "Internet Guest Account".

Once the permissions have been specified, browse to http://localhost/phpBB2 and log on using the administrative username and password that you have specified before.
Test the phpBB Application
To test that phpBB has been installed successfully, create a forum and post some messages to it. Follow these steps:
1. Navigate to http://localhost/phpBB2 and click "Log In."
2. Enter the administrator username and password (this walkthrough used admin/admin).
3. Once logged in, find the link called "" at the bottom of the page. Click it to go to the administration portal.

This causes phpBB to ask you to re-authenticate. It then takes you to the administration panel:

4. In this panel click Management under the Forum Admin group. Enter the name of the forum you want to create and click Create New Forum.

This creates a new forum on your site for posting messages.
Getting More Information
To discuss the FastCGI Extension for IIS 6.0, or file bug reports, please use the FastCGI forums:
To see a list of known issues with the IIS 6.0 FastCGI, see known issues.
To get more information regarding running various PHP applications on IIS, refer to:
Related Content
Comments