Win2003 IIS runs the Php_win server in fastcgi mode

Source: Internet
Author: User
Tags configuration php mysql version php session php code php file upload phpinfo utc greenwich vc9

As a result of PHP5.3 improvements, the original IIS parsing of PHP scripts via ISAPI has not been supported, and PHP has started using Microsoft's FASTCGI model since version 5.3.0, which is a more advanced way to run faster and more stably. This article describes running PHP in fastcgi mode on IIS. Let's take Windows 2003 + IIS 6.0 (windows2003) for 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 latest version of FastCGI 1.5 here. Official address
2. Install MySQL under Windows to select the. msi installation package format, we chose the Mysql-5.5.19-win32.msi, double-click according to the wizard installation can be simple and convenient.
3. PHP we choose to use this version of Php-5.3.8-nts-win32-vc9-x86.zip. "Vc9" is customized for IIS. "NTS" is a non-thread-safe version of the fastcgi installation for PHP.

Step Two: Install files

1. Build a folder on the disk you want to install. We create a Web folder in the root directory of D disk. D:\Web.
2. Create a WWW folder under a Web folder to store your PHP Web site 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, install MySQL to D:\Web\MySQL folder. Specific MySQL installation process can refer to the documentation MySQL installation diagram.
5. Install fastcgi extensions for IIS. First determine that the system has IIS installed. Then double-click Fcgisetup_1.5_x86_rtw.msi installation, if C disk is your Windows system installation disk, it will fcgi specific files copied to the C:\Windows\system32\inetsrv folder, Registering and making the FCGI Web service effective, there is more FastCGI Handler in the Web service extensions for IIS.

Step Three: Configure IIS

1. Click "Control Panel"-> "Administrative Tools"-> "Internet Information Services" (or click "Start"-> "Run"-> enter Inetmgr.exe) to open IIS.
2. Click the "website"-> "right Key-Properties", click "Home directory"-> "Configure"-> "Add" in the Properties dialog bar.
3. In the Add and Edit Application Extension Mappings dialog box, click Browse to find the Fcgiext.dll in C:\Windows\system32\inetsrv. The extension is written ". php", the midpoint of the "action" item is "limited to", write "Get,post,head", put the following two options "script Engine", "Confirm file exists" on the hook. Confirm the configuration.
4. Return to the Site property box, click "Document", add "index.php" as the default page. Finally click "Confirm".
5. Click the "website"-> "right"-new "->" site, set up a new site, the port we set to 8080, the site's main directory path is D:\Web\WWW.

Fourth Step: Configure FastCGI

After you install 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 a file map that extends 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 repeats 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. Implement configuration via 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, respectively, is:

    1. Register PHP to fastcgi.
    2. Instancemaxrequests is used to set application pool recycling. FastCGI the number of process requests reaches instancemaxrequests value 5000, the application pool is automatically recycled. The default value is 1000.
    3. The application pool is automatically recycled when the environment variable php_fcgi_max_requests reaches 10000.
    4. Requesttimeout sets the request timeout, which is the maximum time allowed for the request, and if the FASTCGI process request exceeds this setting, the value is 90 seconds.
    5. ACTIVITYTIMEOUT Specifies the maximum active time requested by the fastcgi process, and during the set time, the FASTCGI process and IIS do not communicate, terminating the process. The default value is 70 seconds.
2. Direct Configuration Fcgiext.ini

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

	[Types]
	 php=php
	[PHP]
	 exepath=d:\web\php\php-cgi.exe

	instancemaxrequests=5000
	environmentvars=php_fcgi _max_requests:10000
	requesttimeout=360
	activitytimeout=120

Hint: "PHP" is the extension, and "PHP" is the configuration section name, defined as "[PHP]".

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

Fifth Step: Configure PHP

Open the PHP installation directory, that is D:\Web\PHP, we can see that the directory has two such files Php.ini-development and Php.ini-production, the first is to develop the use of the configuration file, the second is the configuration of the production environment, because we are doing the development of the local, so choose the former. Copy the php.ini-development to the same directory and rename it to PHP.ini. This php.ini is the configuration file currently in use, and the following steps are modifying the contents of this php.ini file. Also note that the new settings will not take effect until you modify the php.ini file to restart the IIS service. See documentation: Ways to restart the IIS service

1. Set about FastCGI section

Find the following lines, the front quote ";" Remove, set the parameter to the following

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

Please refer to cgi.force-redirect;cgi.fix-pathinfo;fastcgi.impersonate for their instructions.

2. Specify the storage directory for the PHP extension library

PHP extensions in Windows are usually stored as DLLs in PHP's ext directory.
Use the Text tool to open the php.ini file and find Extension_dir = "ext", which is the line under on Windows. Put it in front of the semicolon ";" removed, instead as follows:

    Extension_dir = "D:/web/php/ext"

Extension_dir represents the specific directory of the PHP extension library to invoke the corresponding DLL file.

3. Open the appropriate extension library

By default, many PHP extensions are turned off, such as default PHP does not support the MySQL database connection, you need to open the appropriate extension library.
Here we turn on some common extensions.
Find Windows Extensions (approximately 941 lines), below it 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

Remove the semicolon ";" before extension above. If you want to load other extension modules, 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 Extension=php_mbstring.dll.
Tip 2: If PHP's own extension library 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/download a compiled DLL file, or go to http://museum.php.net/php5/ Load PECL Collection Compression package.
Tip 3: A lot of people are looking for php_zip.dll, in fact, since php5.3 has integrated the zip extension, you can use <?php phpinfo ()?> find the zip extension description.

4. Allow PHP to 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 Let IT support the short label.
PHP code is generally included in the <?php ...? > tags, set short_open_tag = On, can be written in a more concise form: .... ? >.

5. Configure the PHP session function

When using the session function, we have to configure the Save directory on the server for the sessions file. We need to create a read-write directory for the session, preferably separate from the site directory.
Here the directory is built in the D:\Web\sessiontmp, and then found in the php.ini configuration file, Session.save_path = "/tmp" (approximately 1467 lines), remove the preceding semicolon ";" and change to read as follows:

    Session.save_path = "D:/web/sessiontmp"

6. Configure PHP 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 create a read-write directory folder D:\Web\fileuploadtmp and then find it in the php.ini configuration file, Upload_tmp_dir = (about 875 lines), modified to:

    Upload_tmp_dir = "D:/web/fileuploadtmp"

PHP default upload file size of not more than 2M, to upload more than 2M files, please refer to the document configuration PHP.ini implementation file upload function.

7. Set time zone

In the php.ini configuration file look for;d Ate.timezone =, remove the preceding semicolon ";" instead, replace the following:

	Date.timezone = PRC

Date.timezone is the PHP5.1 start of the newly added configuration parameter, which is used to set the time zone. The default Date.timezone is commented out, or the default time zone is UTC Greenwich Mean time.
We change here to Date.timezone = PRC (Prc,people's Republic of China, the People's Republic of China), which is the date of use in the Chinese time zone. This will solve the problem of eight hours difference in time.

Step Sixth: Test

Save the following code as a index.php file and place 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 successful!";
        Mysql_close ();
      ? >
      </div>
      <br/>
      <?php phpinfo ()?>
    </body>

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.