6. configure PHP-FPM-php Tutorial

Source: Internet
Author: User
6, configure PHP-FPM 6, configure PHP-FPM 5.1 Introduction:

The PHP-FPM (FastCGIProcess Manager: FastCGI Process Manager)

The PHP-FPM is a PHPFastCGI manager that is only used for PHP. It provides a better PHP process management method, which can effectively control the memory and processes, and can smoothly reload PHP configurations. it has more advantages than spawn-fcgi, so it is officially recorded by PHP. You can enable PHP-fpm with the enable-FPM parameter in./configure.

Use PHP-FPM to control FastCGI processes of PHP-CGI

/Usr/local/php/sbin/php-fpm {start | stop | quit | restart | reload | logrotate}

-- Start the fastcgi process of php

-- Stop force terminate the fastcgi process of php

-- Quit: smoothly terminate the fastcgi process of php

-- Restart the fastcgi process of php

-- Reload re-smoothly loads php. ini

-- Logrotate re-enable log files

5.2 configure php-fpm:

2.1 provide the SysV init script for php-fpm and add it to the service list:

[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 configuration file of php-fpm:

[Root@webphp-5.5.34] # vim/usr/local/php/etc/php-fpm.conf configure fpm related options for the value you need, pid File: pm is enabled by default. max_children = 50pm. start_servers = 5. min _spare_servers = 2. max_spare_servers = 8

2.4 then you can start php-fpm:

[Root @ web php-5.5.34] # service php-fpm startStarting php-fpm done description: php-fpm available parameter start | stop | force-quit | restart | reload | status

2.5 for ease of use, you can add the PHP command to the 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 # Change PATH = $ PATH: $ HOME/bin to: PATH = $ PATH: $ HOME/bin: /usr/local/php/binPATH = $ PATH: $ HOME/bin:/usr/local/php/bin export PATH save and exit!
Make PHP environment variables take effect: [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 2016 11:22:13) Copyright (c) 1997-2015 The PHP GroupZend 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:

Run the following command to verify the running status (if the command output contains several php-fpm processes, the startup is 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 to Port 9000 of port 127.0.0.1. you can also run the following command to check whether it has been listened on the corresponding 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 enable httpd-related modules

After Apache httpd 2.4, there has been a dedicated module for FastCGI implementation. this module is mod_proxy_fcgi.so, which is actually used as an extension of the mod_proxy.so module. Therefore, both modules must be loaded.

[root@web php-5.5.34]# vim/etc/httpd24/httpd.conf 115 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 configure the VM to support fcgi

1. change the httpd-vhosts.conf configuration to add lines similar to the following in the appropriate 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.52linux.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   ErrorLog "logs/blog_error_log"   CustomLog "logs/blog_access_log" common
  
 
     ServerAdmin webmaster@dummy-host2.example.com    DocumentRoot"/usr/local/apache/htdocs/bbs/"   ServerName bbs.52linux.com    ProxyRequests Off    ProxyPassMatch ^/(.*\.php)$fcgi://127.0.0.1:9000/usr/local/apache/htdocs/bbs/$1   ErrorLog "logs/bbs_error_log"   CustomLog "logs/bbs_access_log"   comomn
 

ProxyRequests Off: disable forward proxy

ProxyPassMatch. the file request ending with php is sent to the php-fpm process. php-fpm must at least know the running directory and URI: the two parameters are specified after 9000. the passing of other parameters has been encapsulated by mod_proxy_fcgi.so and does not need to be specified manually.

2. edit the apache configuration file httpd. conf so that apache can recognize pages in php format and support the php 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 set the location to directoryindexindex.html to 257
 
  
258 DirectoryIndex index.phpindex.html 259
 

In versions earlier than Apache httpd 2.4, either PHP is run as an Apache module or a third-party module is added to support PHP-FPM implementation.


Next Article: VII. phpmyadmin installation

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.