FastCGI is a scalable, high-speed interface for communicating between HTTP server and dynamic scripting languages. Most popular HTTP servers support FASTCGI, including Apache, Nginx, and lighttpd, while FASTCGI is supported by a number of scripting languages, including PHP, which runs in PHP with mod_fastcgi instead of Mod_ Phpsusexec Running PHP acceleration mode.
Characteristics:
1, persistent connection. It's not necessary to start and initialize every request, and it's fast.
2, it is said to allow PHP to execute 3 to 30 times times faster. The reason is that the PHP interpreter is loaded into memory without having to read from memory every time it is needed, greatly improving the performance of the site that relies on the script to run.
3, because there is no need to start and initialization of each request, it also greatly reduces the system resources (CPU) occupation.
4, for the original PHP program is completely without modification.
5. Only one php.ini file is available. When you want to configure multiple php.ini files to accommodate different scripting needs, you want to disable PHP's fast CGI in its subdirectories, so that other directories continue to be valid for CGI.
PHP runs in fastcgi mode under Linux
1. Linux System
[Root@localhost/]# Cat/etc/redhat-release
CentOS Release 5.2 (Final)
2. Installing Apache
Download and unzip Apache, this demo version is 2.2.19
[root@localhost]# wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.19.tar.gz
[root@localhost]# tar Xvzf httpd-2.2.19.tar.gz
To compile and install Apache, the purpose of this article is simply to demonstrate that PHP is running in fastcgi mode, and only select the required parameter compilation for convenience.
[root@localhost]# CD httpd-2.2.19
[Root@localhost]#./configure--enable-so
[Root@localhost] #make
[Root@localhost] #make Install
3, install mod_fcgid (note is mod_fcgid, not mod_fastcgi)
Download and unzip the mod_fcgid, the version used for this test is 2.3.6
[Root@localhost]wget http://labs.renren.com/apache-mirror//httpd/mod_fcgid/mod_fcgid-2.3.6.tar.gz
[Root@localhost]tar Xvzf mod_fcgid-2.3.6.tar.gz
Compiling and installing mod_fcgid
[ROOT@LOCALHOST]CD mod_fcgid-2.3.6
[Root@localhost] Apxs=/usr/local/apache2/bin/apxs./configure.apxs
[Root@localhost]make
[Root@localhost]make Install
Note: Some documents on the network are not APXS=/USR/LOCAL/APACHE2/BIN/APXS, refer to readme-fcgid documents in Mod_fcgid software for details
4. Install PHP
Download and compress the php,php version is 5.3.6
[Root@localhost]wget Http://www.php.net/get/php-5.3.6.tar.bz2/from/cn.php.net/mirror
[Root@localhost]tar XVJF php-5.3.6.tar.bz2
Compiling and installing PHP
[Root@localhost] CD php-5.3.6
[Root@localhost]./configure--prefix=/usr/local--with-configure-file-path=/etc
[Root@localhost]make
[Root@localhost]make Install
Note: If there is a library file error, please install the relevant library files, the author of the system has reported LIBXML2 error, yum install Libxml2-devel, solve the problem. Many documents on the network, said to use--enable-fastcgi this parameter, the author in./configure--help did not find this parameter, but found a--disable-cgi parameter, It is decided not to add--enable-fastcgi this parameter, which confirms that this parameter can not be added thereafter. --WITH-APXS2 This parameter must not be added.
5. Configuration
Creating the FastCGI Script directory
[root@localhost]# Mkdir/usr/local/apache2/fcgi-bin
[root@localhost]# ln-s/usr/local/php/bin/php-cgi/usr/local/apache2/fcgi-bin/php-cgi
Edit Apache configuration file
[root@localhost]# vi/usr/local/apache/conf/httpd.conf
Add the following
scriptalias/fcgi-bin/"/ usr/local/php5/bin/"
AddHandler php-fastcgi. PHP
Action php-fastcgi/fcgi-bin/php-cgi
AddType application/ x-httpd-php. PHP
IdleTimeout
processlifetime 1800
Maxprocesscount 100
Defaultminclassprocesscount 3
Defaultmaxclassprocesscount 8
Ipcconnecttimeout
Ipccommtimeo UT
maxrequestsperprocess
Allowoverr IDE None
Options followsymlinks +execcgi
Order allow,deny
allow from all
Modify
Options Indexes followsymlinks +execcgi
allowoverride None
Order Allow,deny
allow from all
Note: I test the test.php file placed under the Htdocs directory, so htdocs directory permissions need to execcgi, if the directory is different, please give the directory execcgi permissions. Another loadmodule fcgid_module modules/mod_fcgid.so this reload mod_fcgid, automatically added.
6. Verification
Edit Test Page
[root@localhost]# vi/usr/local/apache2/htdocs/test.php
Echo Phpinfo ();
?>
IIS7 Configuration fastcgi running PHP
Environment Description:
Operating System:Using the Windows Server 64-bit system, IIS7.5
PHP Version:Official download PHP 5.4.16 VC9 x86 Non Thread safezip version.
PHP Path:c:php-5.4.16
Configuration steps:
- Unzip the PHP file and change the directory name to the C drive. Directory address is c:php-5.4.16
- Copy php.ini-production renamed to PHP.ini, first refer to php.ini parameter description modification.
and modify PHP support for fastcgi:
- The Winmail site opens by adding related options:
Select "Handler Mappings":
Select Add Module mapping:
Select "Module"-"Fastcgimodule" and PHP Path:
Select "Yes":
Set the "FastCGI" options as shown:
The maximum number of instances and instance maximum requests can be modified according to your own situation.
Maximum instances: If the Windows Server R2 operating system sets the property to 0, you can enable IIS to automatically select the optimal number of FastCGI processes under the current execution environment.
"Instance max Requests": Can be modified according to their own circumstances, can also be modified to 10000.
Add a variable: The php_fcgi_max_requests value is: 10000
http://www.bkjia.com/PHPjc/632622.html www.bkjia.com true http://www.bkjia.com/PHPjc/632622.html techarticle FastCGI is a scalable, high-speed interface for communicating between HTTP server and dynamic scripting languages. Most popular HTTP servers support FASTCGI, including Apache, Nginx, and lighttpd, while ...