Configuration php-5.4.13 in FPM (FastCGI) and Apache interaction

Source: Internet
Author: User
Tags configuration php mcrypt mysql client xsl

Configuration php-5.4.13 in FPM (FastCGI) and Apache interaction


First, the installation of Apache and MySQL is the same as the previous part; Please install it according to it;

Second, compile and install php-5.4.13
1, to resolve the dependency relationship:

# yum-y Groupinstall "X Software Development"

If you want the compiled PHP to support the MCrypt extension, the following two RPM packages need to be installed:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
mhash-0.9.9-1.el5.centos.i386.rpm
mhash-devel-0.9.9-1.el5.centos.i386.rpm

2. Compile and install php-5.4.13
# Tar XF php-5.4.13.tar.bz2
# CD php-5.4.13
#./configure--prefix=/usr/local/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-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2

Note: If you use PHP5.3 or above, you can specify MYSQLND to link to the MySQL database so that you do not need to install the MySQL or MySQL development package first. MYSQLND is available from PHP 5.3 and can be bound to it at compile time (instead of relying on the specific MySQL client library bindings), but it is the default setting starting with PHP 5.4.
#./configure--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd

# make
# Make Intall

3. Provide the configuration file for PHP:
# CP Php.ini-production/etc/php.ini


4, Configuration php-fpm
Provide the SYSV init script for php-fpm and add it to the list of services:
# CP SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM
# chmod +X/ETC/RC.D/INIT.D/PHP-FPM
# chkconfig--add php-fpm
# Chkconfig PHP-FPM on

5. Provide the configuration file for php-fpm:
# cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

To edit a php-fpm configuration file:
# vim/usr/local/php/etc/php-fpm.conf
Configure the relevant options for FPM to the value you need and enable the PID file (the last line below):
Pm.max_children = 50
Pm.start_servers = 5
Pm.min_spare_servers = 2
Pm.max_spare_servers = 8
PID =/usr/local/php/var/run/php-fpm.pid

The above is just the part of the configuration of PHP, to implement the FPM mechanism, also need to configure httpd-2.4.4 this part

Third, configuration httpd-2.4.4

1. Enable the relevant modules of httpd

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
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_fcgi_module modules/mod_proxy_fcgi.so

2. Configure the virtual host to support the use of fcgi

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


For example:
<virtualhost *:80>
DocumentRoot "/www/xsl.com"
ServerName www.xsl.com
Proxyrequests OFF
Proxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/www/xsl.com/$1

<directory "/www/xsl.com" >
Options None
allowoverride None
Require all granted
</Directory>
</VirtualHost>

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.

3, edit Apache configuration file httpd.conf, let Apache can recognize PHP format page, and support the PHP format of the home page

# vim/etc/httpd/httpd.conf
1, add the following two lines
AddType application/x-httpd-php. php
AddType Application/x-httpd-php-source. Phps

2. Locate to DirectoryIndex index.html
Modified to:
DirectoryIndex index.php index.html

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.

Final execution

# service PHP-FPM Start

#service httpd Start

Can

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.
# NETSTAT-TNLP | grep php-fpm
TCP 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm

Use the following command to verify if the command output has several PHP-FPM processes that indicate that the boot was successful:
# PS aux | grep php-fpm

This article from the "Linux Learning Path" blog, declined reprint!

Configuration php-5.4.13 in FPM (FastCGI) and Apache interaction

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.