Six, configuration php-fpm
5.1 Introduction:
PHP-FPM (fastcgiprocess manager:fastcgi process Manager)
PHP-FPM is a phpfastcgi manager and is for PHP only. It provides a better way to manage the PHP process, can effectively control memory and process, can be smooth overloaded PHP configuration, more advantages than spawn-fcgi, so by the official PHP included. The PHP-FPM can be turned on with the ENABLE-FPM parameter when the./configure.
Using PHP-FPM to control the fastcgi process of php-cgi
/usr/local/php/sbin/php-fpm{start|stop|quit|restart|reload|logrotate}
--start starting PHP's fastcgi process
--stop forcing the fastcgi process to terminate PHP
--quit smooth termination of PHP fastcgi process
--restart restarting PHP's fastcgi process
--reload re-load PHP php.ini
--logrotate re-enabling the log file
5.2 Configuration PHP-FPM:
2.1 Provide the SYSV init script for php-fpm and add it to the list of services:
[Root@web tool]# cd php-5.5.34[root@web php-5.5.34]# cpsapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm[root@web php-5.5.34]# chmod +x/etc/rc.d/init.d/php-fpm[root@web php-5.5.34]# chkconfig--addphp-fpm[root@webphp-5.5.34]# Chkconfig PHP-FPM on
2.2 Provide the configuration file for php-fpm:
[root@webphp-5.5.34] # cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
2.3 Edit the PHP-FPM configuration file:
[root@webphp-5.5.34] # vim/usr/local/php/etc/php-fpm.conf The relevant options for configuring FPM are the values you need, the PID file is enabled by default: Pm.max_children = 50pm.start _servers = 5pm.min_spare_servers = 2pm.max_spare_servers= 8
2.4 The next step is to start the PHP-FPM:
[Root@web php-5.5.34]# service php-fpm startstarting php-fpm done Description: php-fpm Available Parameters start|stop|force-quit|restart| Reload|status
2.5 for ease of use, you can add a PHP command to an environment variable
[Root@web php-5.5.34]# vim ~/.bash_profile #. Bash_profile # Get the aliases and Functionsif [-f ~/.BASHRC]; then. ~/.BASHRCFI # User specific environment and startupprograms# path= $PATH: $HOME/bin to: path= $PATH: $HOME/bin:/ Usr/local/php/binpath= $PATH: $HOME/bin:/usr/local/php/bin export PATH Save exit!
Make the PHP environment variable effective: [root@webphp-5.5.34]#. ~/.bash_profile
See PHP version [Root@web php-5.5.34]# php-vphp 5.5.34 (CLI) (BUILT:APR 7 11:22:13) Copyright (c) 1997-2015 the PHP Gr Oupzend Engine v2.5.0, Copyright (c) 1998-2015zend Technologies with XCache v3.1.2, Copyright (c) 2005-2014, by Moo
with XCache Cacher v3.1.2, Copyright (c) 2005-2014, by MOo
5.3 Inspection:
Use the following command to verify if the command output has several PHP-FPM processes that indicate that the boot was successful:
[Root@web php]# Psaux | grep php-fpmroot 54722 0.0 0.3 175728 5932? Ss 20:19 0:00 php-fpm:master process (/usr/local/php/etc/php-fpm.conf) www 54723 0.0 0.2 175728 5144? S 20:19 0:00 Php-fpm:pool www www 54724 0.0 0.2 175728 5144? S 20:19 0:00 Php-fpm:pool www www 54725 0.0 0.2 175728 5144? S 20:19 0:00 Php-fpm:pool www www 54726 0.0 0.2 175728 5144? S 20:19 0:00 Php-fpm:pool www www 54727 0.0 0.2 175728 5144? S 20:19 0:00 Php-fpm:pool www Root 54837 0.0 0.0 103308 852 pts/1 s+ 20:22 0:00 grep php-fpm
By default, FPM listens on port 9000 of 127.0.0.1, and can also use the following command to verify that it is already listening on the appropriate socket.
[Root@web php-5.5.34] #netstat-TNLP | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 54722/php-fpm
5.4 Enabling HTTPD-related modules
After Apache HTTPD 2.4 has a module specifically for the implementation of the FASTCGI, this module is mod_proxy_fcgi.so, it is actually as an extension of the mod_proxy.so module, so the two modules are loaded
[Root@web php-5.5.34]# vim/etc/httpd24/httpd.conf LoadModule proxy_module modules/mod_proxy.so119 LoadModule Proxy _fcgi_modulemodules/mod_proxy_fcgi.so
Then reload the httpd service:
[Root@web php-5.5.34]# Service httpd Reload
5.5 Configuring virtual host support using fcgi
1. Change the httpd-vhosts.conf configuration to add two lines similar to the following in the corresponding virtual host.
Proxyrequests OFF
proxypassmatch^/(. *\.php) $ fcgi://127.0.0.1:9000/path/to/document_root/$1
[Root@web extra]# Vim httpd-vhosts.conf
ServerAdmin webmaster@dummy-host.example.com documentroot "/usr/local/apache/htdocs/www/" ServerName Www.52li nux.com proxyrequests Off proxypassmatch ^/(. *\.php) $fcgi://127.0.0.1:9000/usr/local/apache/htdocs/www/$1 ErrorLog "Logs/www_error_log" Customlog "Logs/www_access_log" Common
ServerAdmin webmaster@dummy-host2.example.com documentroot "/usr/local/apache/htdocs/blog/" ServerName blog. 52linux.com proxyrequests Off proxypassmatch ^/(. *\.php) $fcgi://127.0.0.1:9000/usr/local/apache/htdocs/blog/$1 ERR Orlog "Logs/blog_error_log" Customlog "Logs/blog_access_log" Common
ServerAdmin webmaster@dummy-host2.example.com documentroot "/usr/local/apache/htdocs/bbs/" ServerName bbs.52l inux.com proxyrequests Off proxypassmatch ^/(. *\.php) $fcgi://127.0.0.1:9000/usr/local/apache/htdocs/bbs/$1 ErrorLo G "Logs/bbs_error_log" Customlog "Logs/bbs_access_log" Comomn
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 this is where the two parameters are indicated 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.
2. Edit Apache config file httpd.conf to allow Apache to recognize PHP-formatted pages and support PHP-formatted homepage
[Root@web extra]# vim/etc/httpd24/httpd.conf# 1 Add the following two lines: 388 addtypeapplication/x-httpd-php . php389 AddType Application/x-httpd-php-source. Phps
# 2 position to directoryindexindex.html modified to: 257
258 directoryindex index.phpindex.html259
Add: Apache httpd 2.4 Previous versions, either run PHP as an Apache module or add a third-party module to support the PHP-FPM implementation.
Next: Seven, phpMyAdmin installation