Example of the CentOS 7 system lamp Configuration PHP-FPM

Source: Internet
Author: User
Tags configuration php vps

CentOS 7 system has been out for some time, today we look at the CentOS 7 in the VPS to the Lamp environment configuration PHP-FPM process, hope that the article can help you.

CentOS 7 has been released and is using Apache 2.4 as the default Apache component. I heard that the Apache 2.4 Event mode is very good, and the supporting mod_proxy_fcgi and PHP has been natively supported by PHP-FPM and good performance, plus Google's mod_spdy need to run in the thread safe Environment, the use of CentOS 7 + Apache 2.4 + MariaDB + PHP + php-fpm seems to be a logical thing to do. Because the configuration of PhpMyAdmin match php-fpm is slightly different from the general virtual host, write it together.

Because it is on the ready-made CentOS 7 + PHP + MariaDB + phpMyAdmin on the LAMP server will use mod_php's Apache mpm prefork mode to use PHP-FPM's MPM event mode, therefore Start directly from the installation PHP-FPM, then set the PHP-FPM pool profile, and finally modify the Apache virtual host profile and set the MPM event run parameters.

1. Installing PHP-FPM

Run as root, or sudo to run

Yum Install-y php-fpm

Install the default PHP-FPM installation package for the CentOS release. Yum automatically resolves the installation of dependent packages.

The following 2 configuration files are generated:

/etc/php-fpm.conf/etc/php-fpm.d/www.conf

The previous configuration file does not need to be modified. The latter one is the so-called pool (as some call it "the proxy pools"?).

2. Configure the PHP-FPM pool

Pool configuration files are in the/etc/php-fpm/directory, can have many, the same structure, the name is different, configuration parameters change as needed.

For example, set up a separate configuration file for each virtual host. But a page of water features on this VPS only run a few of their own virtual host, rather than do a shared host use, so on several sites using the same www.conf profile. PHP-FPM's parameter settings can be found here, as well as examples here.

Below is a page of water features currently in use parameters, but also in the test adjustment:

PM = dynamic

Pm.max_children = 9

Pm.start_servers = 2

Pm.min_spare_servers = 1

Pm.max_spare_servers = 4

Pm.max_requests = 500

Because it is not for the shared host, only to run their own several virtual hosts, should not need to create a pool for each virtual host, so here to several virtual hosts using the same www pool. If you need to build a separate pool for each virtual host, please refer to this article.

3. Modify the virtual host configuration file

There are 2 types of files, one is the global Apache configuration file, and the other is the configuration file for each virtual host.

3.1 Global APACHE configuration file and EVENT MPM operating parameters

First, check that if there is a difference, you need to/etc/httpd/conf/httpd.conf the

Index.html

Switch

Index.htm

Because the event mpm and Prefork MPM run differently, the parameter settings are different. And now, after installing Apache in CentOS 7, there are no default parameters in the default profile/etc/httpd/conf/httpd.conf (even the default parameters of Prefork have been removed). Therefore, from a convenient and practical point of view, water features a page recommends that you create a/etc/httpd/conf.d/common.conf file to place such a global, httpd.conf not in the parameters.

Below is a page of water features that is currently in use, but is still being tested to observe and optimize the event MPM running parameters for reference only:

Startservers 2

Serverlimit 16

Minsparethreads 32

Maxsparethreads 128

Threadsperchild 64

Maxrequestworkers 1024

Maxconnectionsperchild 500

Timeout 30

KeepAlive on

Maxkeepaliverequests 100

# 2 or 3 for prefork, but the event or worker can deal with it cleverly, maybe 15?

KeepAliveTimeout 5

# for Fallback

Startservers 8

Minspareservers 8

Maxspareservers 12

MaxClients 50

Serverlimit 50

Maxrequestsperchild 1000

Timeout 30

KeepAlive on

Maxkeepaliverequests 100

# 2 or 3 for Prefork

KeepAliveTimeout 2

Serversignature OFF

Servertokens Prod

It may also be necessary to remind you that a page of water features is currently using the Linode VPS is 1G RAM, basically running this site.

3.2 Modifying the virtual host configuration file

You will then also need to modify the settings in the virtual host configuration file, where the virtual host profile name is vhost.conf and vhostssl.conf (the configuration for SSL encrypted connection access). Here is not a lot of examples, the original configuration please refer to the previous installation configuration LAMP server article.

Water Feature page This VPS is not for the shared server but for purely self-use servers, only a few virtual hosts, so several virtual hosts are in the same file. In short, there is a need to modify the contents of each VirtualHost: add a paragraph in front of the DocumentRoot line,

Proxypassmatch ^/(. *.php (/.*)?) fcgi://127.0.0.1:9000/srv/www/local/html/      $

The Red Font section requires special attention and needs to be consistent with the path behind each documentroot.

In CentOS, the virtual host configuration file is stored in the/ETC/HTTPD/CONF.D directory. For example, when using mod_php, one of the Virtual Host configurations (see here):

ServerAdmin Admin@cnzhx. NetservernameLocal.cnzhx.net Proxypassmatch ^ /(. *.php (/.//127.0. 0.1:9000/srv/www/local/html/ $1 documentroot/srv/www/local/html/# protect wpconfig.php Require all Denied rewriteengine on# BEGIN WordPress ... # END WordPress errorlog  "|/usr/sbin/rotatelogs/srv/www/logs/%y%m%d.www.error.log 86400 480 "Customlog  "|/usr/sbin/rotatelogs/srv/www/logs/%y%m< span class= "variable" >%d.www.access.log 86400 480 "combined        

As mentioned earlier, PhpMyAdmin's virtual host file settings are slightly different, you need to add a statement above the sentence to add a statement containing the PhpMyAdmin directory, such as the following Blue font section,

Proxypassmatch ^/phpmyadmin/(. *.php (/.*)?) $ fcgi://127.0.0.1:9000/srv/www/phpmyadmin/public_html/phpmyadmin/$proxypassmatch ^/ PhpMyAdmin ((. *)?/)fcgi://127.0.0.1:9000/srv/www/phpmyadmin/public_html/phpmyadmin$ 1index.php            

Others remain the same.

4. Finishing, running

Now, just use the/etc/httpd/conf.modules.d/00-mpm.conf in the

LoadModule Mpm_prefork_module modules/mod_mpm_prefork.so

Preceded by the # comment off, then will,

#LoadModule Mpm_event_module modules/mod_mpm_event.so

The previous # is removed.

If you have optimized the Apache module, you need to check the/etc/httpd/conf.modules.d/00-proxy.conf file,

LoadModule proxy_module modules/mod_proxy.so and LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Make sure they are not in front of #.

Restart the PHP-FPM and HTTPD services on the go,

Systemctl Restart PHP-FPM

Systemctl Restart httpd

Http://www.tuicool.com/articles/feAbmui

Example of the CentOS 7 system lamp Configuration PHP-FPM

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.