CentOS 7 System Lamp Configuration PHP-FPM Example

Source: Internet
Author: User
Tags configuration php fpm install php centos vps phpmyadmin

CentOS 7 has been released and uses Apache 2.4 as the default Apache component. I heard that Apache 2.4 Event mode is very good, and the matching mod_proxy_fcgi and PHP has the original support PHP-FPM with the tacit understanding and good performance, plus Google's mod_spdy need to run in the thread safe Environment, instead of CentOS 7 + Apache 2.4 + mariadb + PHP + php-fpm seems to be the logical thing. Because the phpMyAdmin matching PHP-FPM configuration is slightly different from the typical virtual host, write it together.

Because it is in the ready-made CentOS 7 + PHP + mariadb + phpmyadmin LAMP Server will use the mod_php Apache MPM prefork mode to use PHP-FPM MPM event mode, therefore Start directly from the installation PHP-FPM, then set the PHP-FPM pool configuration file, and finally modify the Apache virtual host configuration file and set the MPM event run parameters.

1. Install PHP-FPM

Run as root, or sudo,

Yum Install-y php-fpm
Install the default PHP-FPM installation package for the CentOS release. Yum automatically resolves the dependency pack installation issue.

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 called pool (as some people call it "Agent Pond"?) )。

2. Configure the pool of PHP-FPM

The Pool configuration file is in the/etc/php-fpm/directory, there can be many, like the structure, the name is different, configuration parameters vary according to need.

For example, set up a separate configuration file for each virtual host. But the Waterscape one page of this VPS runs only a few of its own virtual hosts, instead of doing shared host use, so on several sites using the same www.conf profile. PHP-FPM parameter settings can refer to the instructions here, as well as the examples here.

Here 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 intended to be a shared host and only runs several of its own virtual hosts, you should not need to create a pool for each virtual host, so use the same WWW pool for several virtual hosts. Please refer to this article if you need to build a separate pool for each virtual host.

3. Modify the virtual host configuration file

Involves 2 kinds of files, one is the global Apache configuration file, the other is for each virtual host of the configuration file.

3.1 Global APACHE configuration file and EVENT MPM run parameters
First, check that if there is a difference, you need to/etc/httpd/conf/httpd.conf the

DirectoryIndex index.html
To

DirectoryIndex index.php index.html index.htm
Because the event MPM and Prefork MPM run differently, the parameter settings are different. And now that you have Apache installed in CentOS 7, there is no default parameter in the default profile/etc/httpd/conf/httpd.conf (even the default parameters for the previous prefork have been removed). So from a convenient and practical point of view, Waterscape one page recommend yourself to create a/etc/httpd/conf.d/common.conf file to place such global, httpd.conf and no parameters.

Here is a view of the water is currently in use, but also in the test observation and optimization of the event MPM run parameters, for reference only:

<ifmodule mpm_event_module>
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 event or worker can deal with it cleverly, maybe 15?
KeepAliveTimeout 5
</IfModule>

# for Fallback
<ifmodule mpm_prefork_module>
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
</IfModule>

Serversignature off
Servertokens Prod
Also may need to remind, the Waterscape one page currently uses the Linode VPS is 1G RAM, basically is runs this website.

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

Waterscape One page This VPS is not for the shared server but for purely personal use of the server, only a few virtual hosts, so several virtual hosts are in the same file. In short, you need to modify the contents of each virtualhost: add a paragraph in front of the DocumentRoot line,

<ifmodule mpm_event_module>
Proxypassmatch ^/(. *.php (/.*)?) $ fcgi://127.0.0.1:9000/srv/www/local/html/$1
</IfModule>
The Red Font section should be noted in particular, 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, use the configuration of one of the Virtual Host (refer to here) when using mod_php:

<virtualhost *:80>
ServerAdmin admin@cnzhx.net
ServerName local.cnzhx.net
<ifmodule mpm_event_module>
Proxypassmatch ^/(. *.php (/.*)?) $ fcgi://127.0.0.1:9000/srv/www/local/html/$1
</IfModule>
documentroot/srv/www/local/html/
<directory "/srv/www/local/html/" >
# Protect wpconfig.php
<files wp-config.php>
Require All Denied
</files>
Rewriteengine on
# BEGIN WordPress
... ... ...
# End WordPress
</Directory>
ErrorLog "|/usr/sbin/rotatelogs/srv/www/logs/%y%m%d.www.error.log 86400 480"
Customlog "|/usr/sbin/rotatelogs/srv/www/logs/%y%m%d.www.access.log 86400" combined
</VirtualHost>
As mentioned earlier, phpMyAdmin's virtual host file settings are slightly different, and you need to add a statement under the added statement below that contains the phpMyAdmin directory, such as the Blue font section below,

<ifmodule mpm_event_module>
Proxypassmatch ^/phpmyadmin/(. *.php (/.*)?) $ fcgi://127.0.0.1:9000/srv/www/phpmyadmin/public_html/phpmyadmin/$1
Proxypassmatch ^/phpmyadmin ((. *)?/) $ fcgi://127.0.0.1:9000/srv/www/phpmyadmin/public_html/phpmyadmin$1index.php
</IfModule>
Others remain unchanged.

4. Closure, operation

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

LoadModule Mpm_prefork_module modules/mod_mpm_prefork.so
Preceded by the # comment out, and then will,

#LoadModule Mpm_event_module modules/mod_mpm_event.so
Before the # Remove.

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 don't have # in front of them.

and restart the PHP-FPM and HTTPD services.

Systemctl Restart PHP-FPM
Systemctl Restart httpd

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.