Lamp-configuring Apache vs. FPM mode PHP

Source: Internet
Author: User
Tags mcrypt

The installation of Apache and MySQL is the same as the previous part; please follow it for installation;

Version Info: apache-2.4.4, php-5.4.13

second, Compile and install php-5.4.13

1. Resolve Dependencies:

#yum-y groupinstall "X Software development"

If you want to have the compiled PHP support MCrypt extension, you need to download two RPM packages and install Them.

Libmcrypt-2.5.7-5.el5.i386.rpmlibmcrypt-devel-2.5.7-5.el5.i386.rpmmhash-0.9.9-1.el5.centos.i386.rpmmhash-devel-0.9.9-1.el 5.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 with version, in order to link MySQL database, you can specify mysqlnd, so that you do not need to install the MySQL or MySQL development package on this Computer. Mysqlnd is available from php5.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 from the PHP5.4.

#./configure--with-mysql=mysqlnd--with-pdo-mysql=mysqlnd--with-mysqli=mysqlnd#make#make Install

To provide a configuration file for Php:

#cp Php.ini-production/etc/php.ini

3. Configure 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# Chconfig PHP-FPM on

To provide a configuration file for Php-fpm:

#cp/usr/local/php/etc/php-fpm.conf.default/usr/local/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 = 50pm.start_serverss = 5pm.min_spare_servers = 2pm.max_spare_servers = 8
Pid=/usr/local/hp/var/run/php-fpm.pid

The next step is to start php-fpm:

#service php-fpm Start

Verify with the following command (if the command output has a PHP-FPM process in it, the boot is successful):

#ps aux | grep php-fpm

By default, FPM listens on port 9000 of 127.0.0.1, or it can be used to verify that it is already listening on the appropriate socket.

#netstat-tnlp | grep php-fpmtcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm

third, Configuration httpd-2.4.4

1. Enable the appropriate module for HTTPD

After Apache HTTPD 2.4 has been dedicated to a module for the implementation of fastcgi, this module is mod_proxy_fcgi.so, it is actually as an extension of the mod_proxy.so module, so two modules are to be loaded

LoadModule proxy_module modules/mod_proxy.soloadmodule 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 offproxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/path/to/document_root/$1

For example:

<virtualhost *:80> documentroot "/www/xxx.com" ServerName xxx.com serveralias www.xxx.com proxyrequests O FF Proxypassmatch ^/(. *\.php) $ fcgi://127.0.0.1:9000/www/xxx.com/$1 <directory "/www/xxx.com" > Options n One allowoverride none Require all granted </Directory></VirtualHost>

Proxyrequests Off: Turn off the forward proxy

Proxypassmatch: send a file request ending in. php to php-fpm at least you need to know the directory and URI to run, so here is a direct indication of the two parameters after fcgi://127.0.0.1:9000, and the other parameters have been passed Mod_ The proxy_fcgi.so is encapsulated and does not need to be specified manually.

3. Edit Apache config file httpd.conf to enable Apache to recognize php-formatted pages and Support php-formatted homepage

#vim/etc/httpd/httpd.conf

1) Add the following two lines:

AddType application/x-httpd-php. phpaddtype application/x-httpd-php-source. Phps

2) position to DirectoryIndex index.html

Modified To:

DirectoryIndex index.php index.html

Supplement: Apache httpd2.4 Previous versions, either to run PHP as an Apache module, or to add a Third-party module to support the PHP-FPM Implementation.






Lamp-configuring Apache vs. FPM mode PHP

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.