Tags: server application dynamic Interpreter
The version after fastcgi:php-5.3.3 comes with the FPM component,
The FPM component enables the PHP interpreter to work as a daemon and provides an application similar to the Prefork mode that can receive FASTCGI server from the front-end httpd,http-proxy-fcgi reverse proxy user to the backend for dynamic content requests
There are a few areas to note when building a split lamp:
1. Dynamic resources are deployed on the application server (PHP-FPM), and static resources are deployed on the Web server
2, when PHP is working in FPM, it will not be compiled into a httpd module, so compile without using--with-apxs2=/path
parameter, no more LoadModule in the httpd master configuration file Php5_module
Important parameters that need to be turned on when compiling PHP into FPM operation mode--ENABLE-FPM
3, when compiling PHP, you need to connect MySQL or other database management system, it is necessary to enable its related driver module.
4, PHP and MySQL is not the same node, the user account to connect to MySQL needs remote access permissions.Compiling and installing PHP
#tar XF php-5.4.0.tar.bz2
#./configure--prefix=/usr/local/php--with-config-file-path=/etc/php/php.ini--with-config-file-scan-dir=/etc/ php.d/--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir-- Enable-xml--with-mcrypt--with-bz2--with-openssl--with-curl--with-xsl--with-iconv=/usr/local/libiconv-- Enable-sockets--enable-short-tags--enable-static--enable-gd-native-ttf--enable-ftp--enable-maintainer-zts-- With-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd--enable-fpm
#make && make Install
Provide a configuration file for PHP
#cp sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm (Service script)
#chmod +x/etc/rc.d/init.d/php-fpm (add execute permission)
#chkconfig –add php-fpm (added to the list of services)
#chkconfig PHP-FPM on
Providing configuration files for PHP-FPM
Edit the PHP-FPM configuration file, configure the FPM related options for the value you need, and enable the PID file (the last line below):
Listen = 192.168.100.114:9000
Pm.max_children = # # # #静态方式下开启的php number of-FPM processes
Pm.start_servers = 5 # # #动态方式下的起始php number of-FPM processes
Pm.min_spare_servers = 2 # # #动态方式下的最小php number of-FPM processes
Pm.max_spare_servers = 8 # # #动态方式下的最大php number of-FPM processes
PID =/usr/local/php/var/run/php-fpm.pid # # #PID文件路径
Note: If the DM is set to static, then only pm.max_children this parameter takes effect. The system turns on the number of PHP-FPM processes that are set.
If the DM is set to dynamic, then the Pm.max_children parameter is invalidated and the next 3 parameters take effect.
The system starts the Pm.start_servers PHP-FPM process at the beginning of the PHP-FPM run, and then according to the system's
The demand dynamically adjusts the number of php-fpm processes between Pm.min_spare_servers and pm.max_spare_servers.
When the PHP-FPM is used as a standalone daemon, the default listener is on the 127.0.0.1:9000 port, which is the default to allow native
HTTPD process Access, the current environment is httpd and PHP are installed on different servers, so to modify the listening port, so that other hosts
able to access.
When each work in fast-cgi mode, the front-end Web server must communicate with the back-end host with the fcgi module.
#service php-fpm Start
Verify that startup is successful
#netstat –tnlp|grep PHP-FPM
TCP 0 0 192.168.100.114:9000 0.0.0.0:* LISTEN 32873/php-fpm
HTTPD related Configurations
1. Enable the relevant modules of httpd
After the Apache httpd2.4 has a module specifically for the implementation of FASTCGI, this module is mod_proxy_fcgi.so,
It is actually an extension of the mod_proxy.so module, so the two modules are loaded
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_fcgi_module modules/mod_proxy_fcgi.so
Turn on the virtual host switch
2. Configure the virtual host to support the use of fcgi
Add two lines similar to the following in the corresponding virtual host:
Proxypassmatch ^/(. *\.php) $fcgi://127.0.0.1:9000/path/to/document_root/$1
Proxyrequests off: Turn off the forward proxy
Proxypassmatch: Send a file request ending in. php to the PHP-FPM process, php-fpm need to know at least the directory and URI that is running
So the two parameters are indicated here directly after the fcgi://127.0.0.1:9000.
The delivery of other parameters has been encapsulated by mod_proxy_fcgi.so and does not need to be specified manually.
Issues to be aware of:
The dynamic resource needs to be placed on the PHP server, when the HTTPD server receives the dynamic page content requested by the client browser,
will send the request to the specified PHP server for processing, but static pages such as HTML, JPG, etc. will still be on the httpd server
Processing, otherwise information such as images may not be displayed, so when deploying a website, you need to deploy the site's resources separately on both sides.
Create directories of the same path on both the httpd server and the PHP server, or you will get an error when starting the HTTPD service.
To edit a virtual host configuration file:
ServerAdmin [email protected]
Proxypassmatch ^/(. *\.php) $ fcgi://192.168.100.114:9000/data/web/www/$1
Customlog "/usr/local/apache/logs/phpinfo-access_log" common
<directory "/data/web/www/" >
Require all granted
DirectoryIndex index.php index.html
Create a Web Host home page (on PHP server) to test whether httpd can support PHP
Edit the following content:
Test on the client browser:
At this point, the Server API operating mode is: fpm/fastcgi
This article is from the "Boomshakalaka" blog, make sure to keep this source http://yadira.blog.51cto.com/6718656/1758548
Lamp combo PHP works in FPM mode