1 overview
the PHP-FPM (FastCGI process manager:fastcgi Progress Manager) is a PHP FastCGI Manager, for PHP 5.3.3 before PHP, is a patch package designed to integrate FASTCGI process management into the PHP package. If you're using PHP before PHP5.3.3, you'll have to patch it into your PHP source code, which you can use after compiling and installing PHP.
makePHPrun onFPMmode to run, makingPHPform a separate module, not justhttpdunder a module,PHPyou can listen to your own ports. PHPand thehttpcan be installed with two machines, but in general will bePHPand thehttpinstalled under the same host, if you want to install separately, becausehttpServer willPHPdocuments are sent toPHP-FPMThis machine is processed so that at this time the accelerated package XCache needs to be installed inPHP-FPMon this machine. After the installation is complete, you need tohttpmake the appropriate configuration on the server
Note that PHP-FPM (standalone operation) and PHP (module mode operation) is two select one, can only install one,
php-5.3.2 is not supported by default FPM mechanism; need to patch itself and compile the installation, httpd-2.2 : is not supported by default fcgi protocol, you need to compile this module yourself, solution: Compile and install httpd-2.4, php-5.3.3+
: httpd-2.4 : rpm fcgi module PHP-FPM php run on FPM mode
2 Configuration fastcgi
. PHP Configuration
. PHP.ini detailed description of the core configuration:
http://php.net/manual/zh/ini.core.php
. PHP.ini configuration options list:
http://php.net/manual/zh/ini.list.php
. configuration file: /etc/php.ini , /etc/php.d/*.ini
. Module , Restart the Httpd service
. FastCGI mode, restart the php-fpm service
. configuration file Format
. configuration file Php-fpm.conf.default the format is format:
[Foo]:section Header Directive=value
. The comment character: # Purely Annotated information
; used to annotate a bootable instruction
in the newer version, the full use of the ";" Make Comments
. fcgi Service configuration file: /etc/php-fpm.conf,/etc/php-fpm.d/*.conf
. Connection pool:
PM = static|dynamicstatic: Fixed number of sub-processes; Pm.max_childrendynamic: Number of child processes managed in dynamic mode Pm.max_childrenpm.start_serverspm.min_ Spare_serverspm.max_spare_serverspm.max_requests= 500. Ensure that the user running the PHP-FPM process has read and write access to the Session Directory mkdir/var/lib/php/ Sessionchown apache.apache/var/lib/php/session
Configuration httpd the configuration file
Add /etc/httpd/conf.d/fcgi.conf configuration file with the following contents:
Vim/etc/httpd/conf.d/fcgi.conf.directoryindexindex.php.proxyrequestsoff.proxypassmatch ^/(. *\.php) $fcgi:// 127.0.0.1:9000/var/www/html/$1# here's $ latter ref # here if PHP-FCG's PHP is another one, Need to replace 127.0.0.1 with the corresponding machine IP, such as the FPM mode of PHP IP is 172.18.50.73, it is necessary to replace the 127.0.0.1 into 172.18.50.73. If FPM is installed on the machine, fill in the 127.0.0.1. Note: The Proxy_fcgi_module module must be enabled on the HTTPD server to act as a PHP client.
View Modules
Httpd–m |grep fcgicat/etc/httpd/conf.modules.d/00-proxy.conf
fcgi.conf The following two lines are enabled in the configuration file
LoadModule Proxy_modulemodules/mod_proxy.soloadmodule proxy_fcgi_modulemodules/mod_proxy_fcgi.so
in the fastcgi mode, you can implement the virtual host, the related configuration is as follows, note that this is not compiled installation, is through Yum the installation is configured as follows.
Vim/etc/httpd/conf.d/vhosts.confdirectoryindex index.php<virtualhost *:80>servername www.b.netDocumentRoot/ Apps/vhosts/b.netproxyrequests Offproxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/apps/vhosts/b.net/$1< Directory "/apps/vhosts/b.net" >optionsnoneallowoverride +nonerequireall granted</directory></ Virtualhost>
3 CentOS 7 installation LAMP (php-fpm mode )
3.1 Yum installation php-fpm
First to uninstall PHP
Yum Install PHP-FPM
. View PHP-FPM The corresponding configuration file
RPM-QL php-fpm/usr/lib/systemd/system/php-fpm.service/etc/logrotate.d/php-fpm/etc/php-fpm.conf/etc/php-fpm.d/ etc/php-fpm.d/www.conf/etc/sysconfig/php-fpm/run/php-fpm
. PHP-FPM Common configurations
Daemonize= No//Whether the program is running in the background listen = 127.0.0.1:9000//fpm listening address, if changed to listen = 9000 will listen to the native IP 9000 Port listen.backlog= 1// The length of the wait queue-1 means unrestricted listen.allowed_clients= 127.0.0.1//Only which hosts are allowed access, and if this configuration is commented, then all hosts will be able to access, where 127.0.0.1 only allow native access. PM = Dynamic//PM is dynamically running or//static a fixed number of child processes, pm.max_childen//dynamic child process data is managed in dynamic mode pm.start_serverspm.min_spare_ serverspm.max_spare_serverspm.max_requests= 500php_value[session.save_handler] =filesphp_value[session.save_path ] =/var/lib/php/session//Set Session storage location
. Start PHP-FPM
Systemctl Start PHP-FPM
3.2 Compiling and installing php-fpm
INSTALL_PHP_FPM () {echo "now install php-5.6.31.tar.bz2" echo "Install libxml2-devel bzip2-devel libmcrypt-devel,please wait ... "yum -y install openssl-devel libxml2-devel bzip2-devel &>/dev/null | | { echo "something wrong when install openssl-devel Libxml2-devel bzip2-devel,please check local yum resource,script exist now "; exit; }yum -y install libmcrypt-devel &>/dev/null | | { echo "Something wrong when install libmcrypt-devel,please check epel yum resource,script exist now ";exit; }get_package;echo " now Unzip php-5.6.31.tar.bz2,wait a minite "Tar xf /root/package/package." $time "/php-5.6.31.tar.bz2 -c /usr/localecho " now configure php "cd /usr/local/php-5.6.31./configure --prefix=/app/php --with-mysql=/usr/local/mysql --with-openssl -- with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir -- with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml -- enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php -- with-config-file-scan-dir=/etc/php.d --with-bz2 &>/dev/null | | { echo "Something wrong when configure php,script will exist, Please check "; exit; }make &>/dev/null | | { echo "Something wrong when make php,script will exist,please check "; exit; }make install &>/dev/null | | { echo "something wrong when make install php,script will Exist,please check ";exit; }[ -e /etc/php ] | | mkdir /etc/php/cp /usr/local/php-5.6.31/php.ini-production /etc/php/php.inicp /usr/local/php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +x / etc/init.d/php-fpmchkconfig --add php-fpmcp /app/php/etc/php-fpm.conf.default /app/ php/etc/php-fpm.confsed -i.bak ' s/#LoadModule proxy_module modules\/mod_proxy.so/ Loadmodule proxy_module modules\/mod_proxy.so/g ' /app/httpd24/conf/httpd.confsed -i ' s/#LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/loadmodule proxy_fcgi_module modules\/mod_proxy_fcgi.so/g ' /app/httpd24/conf/httpd.conf#config httpdsed -i.bak ' s/directoryindex index.html/directoryindex index.php index.html/g ' /app/httpd24/ conf/httpd.confecho "addtype application/x-httpd-php .php" >> /app/httpd24/conf/httpd.confecho "Addtype application/x-httpd-php-source .phps" >> / app/httpd24/conf/httpd.confecho "Proxyrequests off" >>/app/httpd24/conf/httpd.conf#if your php_fpm is not install in the local host,you should replace 127.0.0.1 with php_fpm host ip.echo "proxypassmatch ^/( . *\.php) $ fcgi://127.0.0.1:9000/app/httpd24/htdocs/\$1 " >>/app/httpd24/conf/httpd.confcat >/app/httpd24/htdocs/index.php <<eof
This article is from the "Sunshine Ops" blog, please be sure to keep this source http://ghbsunny.blog.51cto.com/7759574/1972149
About PHP-FPM of LAMP