Due to the improvement of the PHP5.3, the original IIS through the ISAPI parsing PHP script has not been supported, PHP from 5.3.0 later version of Microsoft's fastcgi mode, which is a more advanced way to run faster and more stable. This article describes running PHP in fastcgi mode on IIS. Let's take Windows 2003 + IIS 6.0 (windows2003) as an example.
First step: 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 Php-5.3.8-nts-win32-vc9-x86.zip
Tips:
1. We use the current version of FastCGI 1.5. Official address
2. Install MySQL under Windows Select the. msi installation package format, we chose Mysql-5.5.19-win32.msi, double-click the wizard to install, simple and convenient.
3. PHP we choose to use this version of Php-5.3.8-nts-win32-vc9-x86.zip. "Vc9" is custom-built for IIS. "NTS" is a non-thread-safe version of the FastCGI installation method for PHP.
Step Two: Install files
1. Build a folder on the disk that you want to install. We create a Web folder under the root directory of the D drive. D:\Web.
2. Create a WWW folder under the Web folder to store your PHP website program. D:\Web\WWW.
3. Extract the downloaded Php-5.3.8-nts-win32-vc9-x86.zip to the D:\Web\PHP folder.
4. Install MySQL database and install MySQL to the D:\Web\MySQL folder. The specific MySQL installation process can refer to the documentation for the MySQL installation diagram.
5. Install the fastcgi extension for IIS. First make sure that IIS is already installed on the system. Then double-click the Fcgisetup_1.5_x86_rtw.msi installation, if the C drive is your Windows system installation disk, it will copy the fcgi specific files to the C:\Windows\system32\inetsrv folder, Register and make the FCGI Web service effective, FastCGI Handler is more in the Web service extension of IIS.
Step Three: Configure IIS
1. Click "Control Panel", "Administrative Tools", "Internet Information Services" (or directly click "Start", "Run", enter Inetmgr.exe) to open IIS.
2. Click "Site", "right"-properties, in the Properties dialog bar, click "Home Directory", "Configuration", "add".
3. In the Add and Edit Application Extension Mappings dialog box, click Browse to locate Fcgiext.dll in C:\Windows\system32\inetsrv. The extension writes ". PHP", "action" in the midpoint "limit to", write "Get,post,head", the following two options "script Engine", "Confirm file existence" tick. Confirm the configuration.
4. Return to the Site properties box, click "Documents" and add "index.php" as the default page. Finally click "Confirm".
5. Click "Website", "right button-new" and "website", establish a new site, the port we set here to 8080, the website home directory path is D:\Web\WWW.
Fourth Step: Configure FastCGI
After installing fastcgi, you have the following three important files in the C:\Windows\system32\inetsrv folder:
Fcgiext.dll-This is the fastcgi control handle dynamic link library. It can process requests for programs that communicate with FASTCGI.
Fcgiext.ini-This is a configuration file that contains file mappings that extend to the fastcgi process. It also contains the configuration of the fastcgi process pool.
Fcgiconfig.js-The 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, one is to implement the configuration through the command line, and the other is to modify the Fcgiext.ini file directly.
1. Configure by 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:5000cscript fcgiconfig.js-set-section: "PHP"-environmentvars:php_fcgi_max_ Requests:10000cscript fcgiconfig.js-set-section: "php"-requesttimeout:360cscript fcgiconfig.js-set-section: "PHP"- activitytimeout:120
The meaning of the script, respectively, is:
- Register PHP to fastcgi.
- Instancemaxrequests is used to set up application pool recycling. FASTCGI process requests reach the instancemaxrequests value of 5000, the application pool is automatically reclaimed. The default value is 1000.
- The application pool is automatically reclaimed when the environment variable php_fcgi_max_requests reaches 10000.
- Requesttimeout sets the request time-out time, which is the maximum time allowed for the request, and if the FASTCGI process request exceeds this setting is disallowed, the value is 90 seconds.
- ACTIVITYTIMEOUT Specifies the maximum active time requested by the fastcgi process, and during the set time, the FASTCGI process and IIS do not communicate and the process is terminated. The default value is 70 seconds.
2. Direct Configuration Fcgiext.ini
Opens C:\windows\system32\inetsrv\fcgiext.ini file, joined
[Types] Php=php[php] exepath=d:\web\php\php-cgi.exeinstancemaxrequests=5000environmentvars=php_fcgi_max_requests : 10000requesttimeout=360activitytimeout=120
Tip: "PHP" means the extension, "PHP" is the configuration section name, defined by "[PHP]".
Copy the above code to the end of Fcgiext.ini and save it.
Fifth Step: Configure PHP
Open the PHP installation directory, that is D:\Web\PHP, we can see that there are two such files in the directory Php.ini-development and Php.ini-production, the first one is the configuration file used for development, the second is the configuration of the production environment, because we are doing the development in this machine, so choose the former. Copy the php.ini-development to the same directory and rename it to PHP.ini. This php.ini is the currently used configuration file, the following steps are to modify the contents of this php.ini file. Also note that you need to restart the IIS service after modifying the php.ini file, and the new settings will not take effect. See documentation: How to restart the IIS service
1. Setting about the FastCGI section
The following lines are found, the preceding quotation marks ";" are removed, the parameters are set as follows
Fastcgi.impersonate = 1cgi.fix_pathinfo= 1cgi.force_redirect = 0
Please refer to cgi.force-redirect;cgi.fix-pathinfo;fastcgi.impersonate for their instructions.
2. Specify a storage directory for the PHP extension library
PHP's extension libraries under windows are usually stored as DLLs in the PHP ext directory.
Use the Text tool to open the php.ini file and look for extension_dir = "ext", which is the line below on Windows. Put it in front of the semicolon ";" Removed and changed to read as follows:
Extension_dir = "D:/web/php/ext"
Extension_dir represents the specific directory of the PHP extension library in order to invoke the appropriate DLL file.
3. Open the appropriate extension library
By default, many PHP extension libraries are closed, such as the default PHP does not support the connection to the MySQL database, you need to open the appropriate extension library.
Here we open some of the commonly used extension libraries.
Find Windows Extensions (about 941 lines), below it is the list of extension.
Find the following extensions:
, Extension=php_curl.dll , Extension=php_gd2.dll, Extension=php_mbstring.dll, Extension=php_exif.dll , Extension=php_mysql.dll , Extension=php_mysqli.dll, Extension=php_pdo_mysql.dll, extension= Php_pdo_odbc.dll, Extension=php_sockets.dll, extension=php_xmlrpc.dll, Extension=php_xsl.dll
Get rid of the semicolon ";" in front of the above extension. If you want to load other extensions, the method is the same, just remove the preceding semicolon.
Tip The 1:exif extension is used to display Exif information for a picture, because the extension requires Mbstring.dll support, so the Extension=php_exif.dll line must be written to the back of the Extension=php_mbstring.dll.
Tip 2: If PHP comes with an extension library that doesn't meet your needs, you can go to pecl.php.net to find and download the library you need. Windows users can go to pecl4win.php.net or http://downloads.php.net/pierre/to download the compiled DLL files, you can go to http://museum.php.net/php5/ Load PECL set of compressed packets.
Tip 3: Many people are looking for php_zip.dll, in fact, since php5.3 has been integrated with the zip extension, you can use <?php phpinfo ()?> to find the zip extension description.
4. Let PHP support short tags
In the php.ini configuration file, look for short_open_tag = OFF (approximately 266 lines) to modify it to: Short_open_tag = on to enable it to support short tags.
PHP code is generally included in the <?php ... > in the label, set Short_open_tag = On, can be written in a more concise form: < .... ? >.
5. Configure the session function of PHP
When using the session function, we must configure the session file to save the directory on the server. We need to create a read-write directory for the session, preferably independent of the site directory.
Here the directory is built in the D:\Web\sessiontmp, and then in the php.ini configuration file, Session.save_path = "/tmp" (about 1467 lines), remove the preceding semicolon ";", instead, as follows:
Session.save_path = "D:/web/sessiontmp"
6. Configure the PHP file upload function
As with the session, when using PHP file Upload function, we must specify a temporary folder to complete the file upload function, or the file upload function will fail.
We create a read-write directory folder D:\Web\fileuploadtmp, which is then found in the php.ini configuration file, Upload_tmp_dir = (approximately 875 lines), modified to:
Upload_tmp_dir = "D:/web/fileuploadtmp"
PHP default upload file size of not more than 2M, to upload files larger than 2M, please refer to the document configuration PHP.ini implementation file upload function.
7. Set the time zone
In the php.ini configuration file find;d Ate.timezone =, remove the preceding semicolon ";" to read as follows:
Date.timezone = PRC
Date.timezone is a newly added configuration parameter for PHP5.1 to set the time zone. The default Date.timezone is commented out, and the default time zone is UTC Greenwich Mean time.
We changed here to Date.timezone = PRC (Prc,people's Republic of China, People's Republic of China), which is the date used in the Chinese time zone. This solves the problem of a time difference of eight hours.
Sixth step: Test
Save the following code as a index.php file, and put it under the D:\Web\WWW directory.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">your MySQL admin account "," your MySQL admin password ") ; if (! $link) echo "MySQL database connection failed!"; else echo "MySQL database connection succeeded!"; Mysql_close (); ? > </div> <br/> <?php phpinfo ();?> </body>
Then enter "http://localhost:8080/index.php" in the browser address bar. The results are as follows:
IIS running PHP in fastcgi mode under Windows