What is PHP fastcgi? fastcgi how to Achieve

Source: Internet
Author: User
Tags bz2 install php ini php file

Characteristics:

1, persistent connection. It is not necessary to start and initialize each request quickly.
2, is said to allow PHP to execute faster than 3 to 30 times times. The reason for this is that the PHP interpreter is loaded into memory instead of reading from memory every time it is needed, greatly enhancing the performance of the site that relies on the script to run.
3. Because it is not necessary to start and initialize each request, the system resource (CPU) consumption is greatly reduced.
4, the original PHP program is completely without modification.
5, only one available php.ini file. When you want to configure multiple php.ini files to accommodate different scripting needs, you can 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. Install Apache
Download and extract Apache, this article shows the 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 runs in fastcgi mode, and for convenience, select only the necessary parameter compilation
[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 extract mod_fcgid, the version used in 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

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 fault, yum install libxml2-devel, solve the problem. Many documents on the network, said to use--enable-fastcgi this parameter, the author in the./configure--help not found this parameter, but found a--disable-cgi parameters, Therefore, it is decided not to add--enable-fastcgi this parameter, then confirm this parameter can not add. --WITH-APXS2 This parameter must not be added.

5. Configure

Create 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 content
scriptalias/fcgi-bin/"/usr/local/php5/bin/"
AddHandler php-fastcgi. php
Action php-fastcgi/fcgi-bin/php-cgi
AddType application/x-httpd-php. php
<ifmodule mod_fcgid.c>
IdleTimeout 300
Processlifetime 1800
Maxprocesscount 100
Defaultminclassprocesscount 3
Defaultmaxclassprocesscount 8
Ipcconnecttimeout 15
Ipccommtimeout 300
Maxrequestsperprocess 100
</IfModule>
<Directory/usr/local/apache2/fcgi-bin>
AllowOverride None
Options FollowSymLinks +execcgi
Order Allow,deny
Allow from all
</Directory>
Modify
<directory "/usr/local/apache2/htdocs" >
Options Indexes followsymlinks +execcgi
AllowOverride None
Order Allow,deny
Allow from all
</Directory>

Note: The author of the test test.php file placed under the Htdocs directory, so htdocs directory permissions need to execcgi, if the directory is different, please give directory execcgi permissions. Another loadmodule fcgid_module modules/mod_fcgid.so this reload mod_fcgid, automatically added.

6. Verify

Edit Test Page
[root@localhost]# vi/usr/local/apache2/htdocs/test.php
<?php
Echo Phpinfo ();
?>

IIS7 Configure FASTCGI to run PHP

Environment Description:

operating system: using Windows 2008 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:

    1. Unzip the PHP file, modify the directory name and put it in C disk. Directory address is c:php-5.4.16
    2. Copy php.ini-production renamed to PHP.ini, first refer to php.ini parameter description modification.
      and modify PHP support for fastcgi:
    3. Winmail site Open Press the following figure to add the relevant options:
      Select Handler mappings:



      Select "Add Module mapping":



      Select "Modules"-"Fastcgimodule" and PHP Paths:



      Select "Yes":



      Set the "FastCGI" related options as shown in the following figure:





      The "Maximum number of instances" and "Maximum number of instances" in the figure above can be modified according to their circumstances.
      Maximum number of instances: If the Windows Server 2008 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 maximum requests": can be modified according to their own circumstances, or can be modified to 10000.
      Add a variable: The php_fcgi_max_requests value is: 10000

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.