In Windows, IIS runs PHP in FastCGI mode. iisfastcgi_PHP tutorial-php Tutorial

Source: Internet
Author: User
Tags php session php file upload php website utc greenwich vc9 zip extension
In Windows, IIS runs PHP and iisfastcgi in FastCGI mode. In Windows, IIS runs PHP in FastCGI mode. iisfastcgi, due to PHP5.3 improvement, the original IIS parsing PHP scripts through isapi is not supported, PHP versions later than 5.3.0 use IIS in Windows to run PHP in FastCGI mode, iisfastcgi

Due to improvements in PHP5.3, the original IIS parsing of PHP scripts through isapi is no longer supported. PHP starts to use Microsoft's fastcgi mode in versions later than 5.3.0, which is a more advanced method, faster and more stable. This article describes how to run PHP in FastCGI mode on IIS. Take Windows 2003 + IIS 6.0 (Windows) as an example.

Step 1: Download the installed file

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

Tip:
1. here we use the latest FastCGI 1.5. Official address
2. install MySQL under Windows select. msi installation package format, we select the mysql-5.5.19-win32.msi, double-click according to the wizard to install, simple and convenient.
3. phpwe choose to use php-5.3.8-nts-win32-vc9-x86.zip. "Vc9" is customized for IIS. "NT" is a non-thread-safe version. it is applicable to the FastCGI installation method of PHP.

Step 2: install the file

1. create a folder on the disk to be installed. Create a Web folder under the root directory of drive D. D: \ Web.
2. create a WWW folder under the Web folder to store your PHP website programs. D: \ Web \ WWW.
3. decompress the downloaded php-5.3.8-nts-win32-vc9-x86.zip file to the D: \ Web \ PHP folder.
4. install the MySql database and install MySQL in the D: \ Web \ MySQL folder. For details about the MySQL installation process, refer to the MySQL installation diagram.
5. install FastCGI Extension for IIS. First, make sure that the system has already installed IIS. Double-click fcgisetup_1.5_x86_rt1_msi for installation. If drive C is your Windows system installation disk, it will copy the fcgi-specific file to the C: \ Windows \ system32 \ inetsrv folder, register and make the fcgi web service take effect. FastCGI Handler is added to the "Web service extension" of IIS.

Step 3: Configure IIS

1. click "control panel"-> "administrative tools"-> "internet information service" (or directly click "Start"-> "run"-> enter inetmgr.exe) to open IIS.
2. click "website"-> "right-click"-properties ", and click" main directory "->" configuration "->" add "in the attribute dialog box ".
3. in the "add and edit application extension ing" dialog box, click browse and find fcgiext. dll in C: \ Windows \ system32 \ inetsrv. Enter ". in php, click "limit as" in the "action" item, write "GET, POST, HEAD", and check the following two options: "script engine" and "check whether the file exists. Confirm the configuration.
4. return to the website property box, click "document", and add "index. php" as the website property page. Click "OK ".
5. click "website"-> "right-click-new"-> "website" to create a new site. Here we set the port to 8080 and the main directory path of the website to D: \ Web \ WWW.

Step 4: Configure FastCGI

After FastCGI is installed, there are three important files in the C: \ Windows \ system32 \ inetsrv folder:

Fcgiext. dll-this is the dynamic link library of the fastcgi control handle. It can process requests for programs that communicate with fastcgi.
Fcgiext. ini-this is the configuration file that contains the file ing that extends to the fastcgi process. It also contains the fastcgi process pool configuration.
Fcgiconfig. js-the extension of fastgci configuration. This script updates the fcgiext. ini file and modifies the iis metalibrary. if necessary, the web service application pool is used again.

There are two methods to configure FastCGI: one is to implement configuration through the command line, and the other is to directly modify the fcgiext. ini file.

1. configure through command line

Open the command line and convert the address to 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: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 is:

2. directly configure fcgiext. ini

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

[Types]  php=PHP[PHP]  ExePath=D:\Web\php\php-cgi.exeInstanceMaxRequests=5000EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000RequestTimeout=360ActivityTimeout=120

Tip: "php" indicates the extension. "PHP" indicates the configuration section name, which is defined in "[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 the directory contains two such files: php. ini-development and php. ini-production: The first is the configuration file used for development, and the second is the configuration of the production environment. because we develop on the local machine, select the former. Copy php. ini-development to the same directory and rename it php. ini. This php. ini is the configuration file currently in use. the following steps are to modify the content of this php. ini file. In addition, you need to restart the IIS service after modifying the php. ini file. The new settings will take effect. See the document: how to restart the IIS service

1. set FastCGI

Find the following lines, then remove the quotation mark ";" and set the parameter to the following

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

For their descriptions, see cgi. force-redirect; cgi. fix-pathinfo; fastcgi. impersonate.

2. specify the directory for storing the PHP Extension Library

In Windows, PHP extension libraries are usually stored in the ext directory of PHP in the form of DLL.
Use a text tool to open the php. ini file and find extension_dir = "ext", that is, the line under On windows. Replace the semicolon ";" in front of it with the following:

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

Extension_dir indicates the Directory of the PHP Extension Library to call the corresponding DLL file.

3. enable the corresponding extension Library

By default, many PHP extension libraries are closed. for example, PHP does not support connection to the Mysql database by default, you need to enable the corresponding extension libraries.
Here we start some common extension libraries.
Search; Windows Extensions (approximately 941 rows), under which is the extension list.
Find the following extension:

        ;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 the extension. If you want to load other extension modules in the same way, just remove the semicolon.
Tip 1: The Exif extension is used to display the exif information of an image. because the extension requires the support of mbstring. dll, you must write the line extension = php_exif.dll to the end of extension = php_mbstring.dll.
Tip 2: If the PHP Extension Library cannot 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 the http://downloads.php.net/pierre/ to download the compiled DLL file, you can also go to the http://museum.php.net/php5/ to load the PECL collection compressed package.
Tip 3: many people are looking for php_zip.dll. In fact, the zip extension has been integrated since php5.3. you can use Find the zip extension description.

4. allow PHP to support short labels

In the php. ini configuration file, search for short_open_tag = Off (approximately in line 266) and change it to: short_open_tag = On to support short labels.
Php code is generally included in After short_open_tag = On is set, you can write it in a more concise form: .

5. configure the PHP Session function

When using the session function, we must configure the session file storage directory on the server. We need to create a read/write Directory for the session, which is better independent from the website directory.
The directory is built on D: \ Web \ sessiontmp, and then in php. ini configuration file; session. save_path = "/tmp" (approximately 1467 rows), remove the semicolon ";" and change it to the following:

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

6. configure the PHP file upload function

Like session, when using the PHP file upload function, we must specify a temporary folder to complete the file upload function. Otherwise, the file upload function will fail.
Create a readable directory folder D: \ Web \ fileuploadtmp, and find it in the php. ini configuration file; upload_tmp_dir = (approximately 875 rows), and change it:

        upload_tmp_dir = "D:/Web/fileuploadtmp"

PHP uploads files up to 2 MB by default. to upload files larger than 2 MB, see configure php. ini to upload files.

7. set the time zone

Search for the php. ini configuration file; date. timezone =, remove the semicolon ";" and change it to the following:

date.timezone = PRC

Date. timezone is a newly added configuration parameter in PHP5.1, which is used 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, People's Republic of China), that is, the date uses the China time zone. In this way, the time difference is solved by eight hours.

Step 6: test

Save the following code as the index. php file and put it under the D: \ Web \ WWW directory.

                
         Test Server                            

Your mysql management account","Your mysql password"); If (! $ Link) echo "MySQL database connection failed! "; Else echo" MySQL database connection successful! "; Mysql_close ();?>


Enter "http: // localhost: 8080/index. php" in the address bar of the browser ". The result is shown in:

Because of improvements in PHP5.3, the original IIS parsing of PHP scripts through isapi is not supported. PHP is used in versions later than 5.3.0...

Related Article

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.