Running PHP in fastcgi mode with IIS in Win2003


Due to the improvement of PHP 5.3, the original IIS parsing PHP script through ISAPI has not been supported. PHP started to use Microsoft’s fastcgi mode from the version after 5.3.0, which is a more advanced way, running faster and more stable. This article introduces running PHP in fastcgi mode on IIS. We take Windows 2003 + IIS 6.0 as an example.

Step 1: download the installed files

1. Fastcgi version fcgisetup 1.5 x86 rtw.msi
2. MySQL version mysql-5.5.19-win32.msi
3. PHP version

1. We use the latest version of fastcgi 1.5. Official address
2. For MySQL installation under windows, choose the. MSI installation package format. We choose mysql-5.5.19-win32.msi. Double click to install according to the wizard, which is simple and convenient.
3. For PHP, we choose “Vc9” is customized for IIS. “NTS” is a non thread safe version of fastcgi for PHP.  

Step 2: install files

1. Create a folder on the disk you want to install. We create a web folder at the root of disk D. D:\Web.
2. Create a WWW folder under the web folder to store your PHP website program. D:\Web\WWW。
3. Unzip the downloaded to the D: \ web \ PHP folder.
4. Install MySQL database, and install MySQL into D: \ web \ MySQL folder. For the specific MySQL installation process, please refer to the MySQL installation diagram.
5. Install fastcgi extension for IIS. First, make sure that IIS is installed on the system. Then double-click fcgisetup? 1.5? X86? Rtw.msi to install. If Disk C is your Windows system installation disk, it will copy the fcgi specific files to the C: \ windows \ system32 \ inetsrv folder, register and make fcgi’s Web service effective. At this time, fastcgi handler is added to the “web service extension” of IIS.

Step 3: configure IIS

1. Click “control panel” – > “management tools” – > “Internet information services” (or directly click “start” – > “run” – > input inetmgr.exe) to open IIS.
2. Click “website” – > “right click property”, and click “home directory” – > “configuration” – > “add” in the property dialog box.
3. In the add and edit application extension mapping dialog box, click Browse to find fcgiext.dll in C: \ windows \ system32 \ inetsrv. For the extension, write “. PHP”, “limit to” in the action item, and “get, post, head”. Check the following two options “script engine” and “confirm whether the file exists”. Confirm the configuration.
4. Return to the website property box, click “document”, and add “index. PHP” as the default page. Finally, click “confirm”.
5. Click “website” – > “right click new” – > “website” to create a new website. The port here is set as 8080, and the main directory path of the website is D: \ web \ www.

Step 4: configure fastcgi

After installing fastcgi, there are three important files in the C: \ windows \ system32 \ inetsrv folder:

Fcgiext.dll – this is the fastcgi handle DLL. It can process requests for programs that communicate with fastcgi.
Fcgiext.ini – this is the configuration file that contains the file mapping that extends to the fastcgi process. It also includes the configuration of the fastcgi process pool.
Fcgiconfig.js – an extension of this configuration fastgci. This script updates the fcgiext.ini file, modifies the IIS metabase, and reuses the web service application pool if necessary.

There are two ways to configure fastcgi here. One is through the command line, and the other is to directly modify the fcgiext.ini file.

1. Configuration through command line

Open the command line, convert the address to C: \ windows \ system32 \ inetsrv, and enter the following command

	cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"D:\Web\php\php-cgi.exe"
		cscript fcgiconfig.js -set -section:"PHP" -InstanceMaxRequests:5000
		cscript fcgiconfig.js -set -section:"PHP" -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
		cscript fcgiconfig.js -set -section:"PHP" -RequestTimeout:360
		cscript fcgiconfig.js -set -section:"PHP" -ActivityTimeout:120

The meaning of the script is as follows:

  1. Register PHP to fastcgi.
  2. Instancemaxrequests is used to set up application pool recycling. When the number of fastcgi process requests reaches the instancemaxrequests value of 5000, the application pool will automatically recycle. The default is 1000.
  3. When the environment variable PHP fcgi Max requests reaches 10000, the application pool will be recycled automatically.
  4. Requesttimeout sets the request timeout, which is the maximum time allowed for the request. If a fastcgi process request exceeds this setting, it will be forbidden, with a value of 90 seconds.
  5. Activitytimeout specifies the maximum active time requested by the fastcgi process. If there is no communication between the fastcgi process and IIS within the set time, the process will be terminated. The default is 70 seconds.
2. Directly configure fcgiext.ini

Open the C: \ windows \ system32 \ inetsrv \ fcgiext.ini file and join



Tip: “PHP” means extension, and “PHP” is configuration section name, defined by “[PHP]”.

Copy the above code to the end of fcgiext.ini and save it.

Step 5: configure PHP

Open the PHP installation directory, that is, D: \ web \ PHP. We can see that there are two such files php.ini-development and php.ini-production in the directory. The first is the configuration file for development and use, and the second is the configuration of the production environment. Because we are developing on our own machine, we choose the former. Make a copy of php.ini-development to the same directory, and change its name to php.ini. This php.ini is the current configuration file. The following steps are to modify the contents of this php.ini file. In addition, it should be noted that after modifying the php.ini file, IIS service needs to be restarted before the new settings take effect. See document: how to restart IIS service

1. Set fastcgi

Find the following lines, remove the preceding quotation mark “;, and set the parameters as follows

	fastcgi.impersonate = 1
		cgi.fix_pathinfo= 1
		cgi.force_redirect = 0

For their descriptions, please refer to cgi.force-redirect; cgi.fix-pathinfo; fastcgi.impersonate.

2. Specify the storage directory of PHP extension library

In windows, the extension library of PHP is usually stored in the EXT directory of PHP in the form of DLL.
Use the text tool to open the php.ini file, and look for the line “extension” dir = “ext”, which is under on windows. Remove the semicolon “;” in front of it and change it to the following:

    extension_dir = "D:/Web/PHP/ext"

Extension? Dir indicates the specific directory of the PHP extension library to call the corresponding DLL file.

3. Open the corresponding extension library

By default, many PHP extension libraries are closed. For example, the default PHP does not support connecting to MySQL database, so you need to open the corresponding extension library.
Here we open some common extension libraries.
Find; windows extensions (about 941 lines), below which is the extension list.
Find the following extension:


Remove the semicolon “;” in front of the extension above. If you want to load other extension modules, you can do the same thing by removing the semicolon.
Tip 1: the EXIF extension is used to display the EXIF information of pictures. Because the extension needs mbstring.dll support, the line extension = php_exif.dll must be written after extension = php_mbstring.dll.
Tip 2: if the PHP extension library can’t meet your needs, you can go to to find and download the library you need. Windows users can go to or, download the compiled DLL file, or go to, and load the PECL set compression package.
Tip 3: many people are looking for php_zip.dll. Actually, the zip extension has been integrated since php5.3. You can use

Find the description of the zip extension.

4. Enable PHP to support short tags

In the php.ini configuration file, look for short ﹣ open ﹣ tag = off (about 266 lines) and change it to: short ﹣ open ﹣ tag = on to support short tags.
PHP code is usually contained in

In the tag of, you can set short_open_tag = on to write in a more concise form:

 .... ?>

5. Configure the session function of PHP

When using the session function, we must configure the directory where session files are saved on the server. We need to create a read-write directory for the session, which is better independent of the website directory.
Here, the directory is built in D: \ web \ session TMP, and then find it in the php.ini configuration file; session.save_path = “/ tmp” (about 1467 lines), remove the previous semicolon “;”, and change it to the following:

    session.save_path = "D:/Web/sessiontmp"

6. Configure the file upload function of PHP

As with session, when using PHP file upload function, we must specify a temporary folder to complete the file upload function, otherwise the file upload function will fail.
We set up a read-write directory folder D: \ web \ fileuploadtmp, and then find it in the php.ini configuration file. Upload_tmp_dir = (about 875 lines), and change it to:

    upload_tmp_dir = "D:/Web/fileuploadtmp"

The default upload file size of PHP is no more than 2m. To upload files larger than 2m, please refer to the document “configuring php.ini to realize the file upload function”.

7. Set time zone

Find in the php.ini configuration file; date. Timezone =, remove the previous semicolon “;” and change it to the following:

	date.timezone = PRC

Date.timezone is a new configuration parameter added at the beginning of PHP 5.1 to set the time zone. The default date.timezone is commented out, that is, the default time zone is UTC Greenwich mean time.
Here we change to date. Timezone = PRC (PRC, people’s Republic of China), that is, the date uses the time zone of China. This can solve the problem that the time difference is eight hours.

Step 6: Test

Save the following code as an index.php file, and put it under the D: \ web \ www directory.

Test server

Then enter “http: / / localhost: 8080 / index. PHP” in the browser address bar. The results are as follows: