Under Win2003 IIS to run PHP FastCGI mode

Due to the improved PHP5.3, the original IIS by isapi parse the PHP script has not been supported, PHP 5.3.0 from future versions of Microsoft started using fastcgi mode, which is a more advanced way to run faster, more stable. This article describes PHP to run on IIS FastCGI mode. We have Windows 2003 + IIS 6.0 (windows2003 own), for example.

Step One: Download the installation file

1. FastCGI version  fcgisetup_1.5_x86_rtw.msi
2. MySQL version of  MySQL-5.5.19-win32.msi
3. PHP version  php-5.3.8-nts-Win32-VC9-x86.zip

Tip:
1. Here we use the latest version of FastCGI 1.5. The official address
2. Windows installation on the choice of MySQL under the .msi installation package format, we chose mysql-5.5.19-win32.msi, double-click the wizard to install, simple and convenient.
3. PHP php-5.3.8-nts-Win32-VC9-x86.zip we choose to use this version. "Vc9" IIS is customizable. "Nts" non-thread-safe version, FastCGI for PHP installation. 

Step 2: Install File

1. build a folder on the disk to be installed. We create a Web folder in the root directory of the D drive. D: \ Web.
2. Create a folder in the Web WWW folder used to store your PHP web application. D: \ Web \ WWW.
3. Place the downloaded php-5.3.8-nts-Win32-VC9-x86.zip extract to D: \ Web \ PHP folder.
4. Install MySql database, the MySQL installation to D: \ Web \ MySQL folder. DETAILED MySQL installation process may reference documents MySQL installation diagram .
5. Installation for IIS FastCGI extension. First, determine the system already installed IIS. Fcgisetup_1.5_x86_rtw.msi then double-click the installation, if the C drive is your Windows installation disk, it will be copied to C fcgi specific file: \ Windows \ system32 \ inetsrv folder under, registration and entry into force of the fcgi of web services, then in the IIS's "Web service extensions" in more than a FastCGI Handler.

Step Three: Configure IIS

1. Click on "Control Panel" -> "Administrative Tools" -> "internet information services" (or click "Start" -> "Run" -> Input inetmgr.exe), open the IIS.
2. Click on the "Site" -> "Right - Properties", click on the "Home Directory" in the Properties dialog box -> "Configuration" -> "Add."
3. In the "Add and Edit Application Extension Mapping" dialog box, click Browse, locate C: \ Windows \ \ inetsrv of fcgiext.dll system32. Extension write ".php", "action" entry point "is limited to" write "GET, POST, HEAD", the following two options for "scripting engine", "Verify that file exists" are on the hook. Confirm the configuration.
4. Return to Site Properties box, click on the "Documents", adding "index.php" as the default page. Finally click "OK."
5. Click on the "Site" -> "Right - New" -> "Web site" to create a new site, set the port here is 8080, the site's home directory path is D: \ Web \ WWW.

Step Four: Configure FastCGI

After installing FastCGI, in C: \ Windows \ system32 \ inetsrv folder has the following three important documents:

fcgiext.dll - This is fastcgi handle dynamic link library. It can handle the request for the program to communicate with fastcgi.
fcgiext.ini - This is the configuration file that contains extended to fastcgi process of file mapping. It also contains the configuration process fastcgi pool.
fcgiconfig.js - This configuration fastgci expansion. This script updates fcgiext.ini file, modify iis cell library, if necessary, re-use web service application pool.

Here configured FastCGI two ways, one is achieved by the configuration command, directly modify fcgiext.ini another file.

1. The configuration achieved through the command line

Open a command line to convert the address into the C: \ Windows \ system32 \ inetsrv, 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

Meaning the script, namely:

  1. Sign up to PHP FastCGI.
  2. InstanceMaxRequests to set the application pool recycling. FastCGI process requests InstanceMaxRequests value reaches 5000, the application will automatically recovered pool. The default value is 1000.
  3. When the environment variable PHP_FCGI_MAX_REQUESTS reach 10,000 automatically recycle the application pool.
  4. RequestTimeout set request timeout, which is the maximum time allowed for a request, if the FastCGI process requests exceed this setting is disabled, the value is 90 seconds.
  5. ActivityTimeout FastCGI process requests specified maximum active time, within the set time, IIS FastCGI process and there is no communication, it will terminate the process. The default is 70 seconds.
2. Direct configuration fcgiext.ini

Open C: \ windows \ system32 \ inetsrv \ fcgiext.ini file, add

	[Types]
	 php=PHP
	[PHP]
	 ExePath=D:\Web\php\php-cgi.exe

	InstanceMaxRequests=5000
	EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000
	RequestTimeout=360
	ActivityTimeout=120

Tip: "php" represent an extension, "PHP" is the name of the configuration section to "[PHP]" definition.

Copy the above code to the end of fcgiext.ini save enough.

Step Five: Configure PHP

Open the PHP installation directory, ie D: \ Web \ PHP, we can see two such file php.ini-development and php.ini-production directory, the first one is to develop configuration files, the second it is the configuration of the production environment, because we are in the development of this machine to do, so I chose the former. A copy php.ini-development into the same directory, and renamed the php.ini. This is currently used php.ini configuration file, the following steps are modified in this php.ini file. Also to be noted that after the php.ini file must restart the IIS service, the new settings to take effect. See the document: How to restart the IIS service method

1. portion disposed about FastCGI

Locate the following lines, that the foregoing quotation mark ";" removed, is set to the following parameters

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

Refer to the description thereof cgi.force-the redirect ; cgi.fix-The pathinfo ; fastcgi.impersonate .

2. Specify the directory where PHP extensions

In Windows PHP extension libraries usually stored in the PHP ext directory to DLL form.
Use the Text tool to open the php.ini file, find the extension_dir = "ext", that is, On windows below the line. Before it was semicolon ";" removed, replaced by the following:

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

extension_dir represent specific PHP extensions library catalog, so that the corresponding DLL files.

3. Open the appropriate extensions

By default, many PHP extension libraries are closed, such as the default PHP does not support connection Mysql database, need to open the appropriate extensions.
Here we open some common extensions.
Find; Windows Extensions (probably in 941 rows), in which the following is a 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

Above the front extension semicolon ";" removed. If you want to load the other extension modules, the same method as long as to remove the front semicolon.
Tip 1: Exif extension is used to display the picture of exif information, because the expansion needs mbstring.dll support, so the extension = php_exif.dll this line must be written back php_mbstring.dll the extension =.
Tip 2: If the built-in PHP extension libraries can not meet your needs, you can go  pecl.php.net  find and download the library you need. windows users can go  pecl4win.php.net  or  http://downloads.php.net/pierre/  download has been compiled DLL file, you can go http://museum.php.net/php5/  contained a collection of PECL archive .
Tip 3: Many people are looking for php_zip.dll, in fact, from the beginning has been integrated php5.3 zip extension, you can find a description of zip extension <php phpinfo ()??> .

4. Let the support PHP short tags

Find short_open_tag = Off in your php.ini configuration file (probably in the 266 line) change that to: short_open_tag = On allowed to support short tags.
<?? php ....> php code after the tag is generally included in the set short_open_tag = On, can be written in a more concise form: <....??>.

The functional configuration of PHP Session

When using session functionality, we must configure the directory where you saved session file on the server. We need to create a readable and writable directory session, the directory of the best independent web directory.
Here was built on the directory in the D: \ Web \ sessiontmp, and then find the php.ini configuration file; session.save_path = "/ tmp" (probably in the 1467 line), remove the front of the semicolon ";" instead as follows:

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

6. PHP configuration file upload function

Like the session, when using PHP file upload function, we have to specify a temporary folder to complete the file upload function, otherwise the file upload function will fail.
We have established a writable directory folder D: \ Web \ fileuploadtmp, and then locate the php.ini configuration file; upload_tmp_dir = (about 875 lines), amended as follows:

    upload_tmp_dir = "D:/Web/fileuploadtmp"

The default PHP upload file size of no more than 2M, in order to upload files larger than 2M, refer to the documentation   php.ini configuration file uploads function .

7. Set the time zone

Find php.ini configuration file; date.timezone =, remove the front semicolon ";" read as follows:

	date.timezone = PRC

PHP5.1 start date.timezone is added configuration parameters, to set the time zone. The default date.timezone is commented out, which is the default time zone is UTC Greenwich Mean Time.
Here we changed date.timezone = PRC (PRC, People's Republic of China, People's Republic of China), which is the date the use of Chinese time zone. This eight-hour difference in time to solve the problem.

Step Six: Testing

Save the following code for the index.php file, into the D: \ Web \ WWW directory.

<! DOCTYPE HTML the PUBLIC "- // the W3C // DTD XHTML 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<HTML xmlns = "HTTP : //www.w3.org/1999/xhtml "> 
    <head> 
    <Meta HTTP-equiv =" the Type-the Content "Content =" text / HTML; charset = UTF-. 8 "/> 
    <title> test server </ title> 
    </ head> 
    <body> 
      <div style = "text-align = left: Center; Color: Red"> 
      ? <PHP 
        $ Link = mysql_connect ( "localhost", "your mysql management account", "your mysql management password "); 
        ! IF ($ Link) echo" MySQL database connection failed! "; 
        the else echo" MySQL database connection success ";! 
        mysql_close ();
      ?>
      </div>
      <br/>
      <?php phpinfo(); ?>
    </body>
</html>

Then in the browser address bar enter "http: // localhost: 8080 / index.php". The results shown below:

Guess you like

Origin www.cnblogs.com/ydwzhang/p/11921286.html