Compile and install LAMP + XCache in FastCGI Mode

Source: Internet
Author: User
Tags mcrypt

I. Working Mode of php

Php has three working modes in the lamp environment: CGI Mode, apache module, and FastCGI mode. Running PHP in CGI Mode has poor performance. Run as an apache module. Compile and install lamp in the previous log. The FastCGI method differs from the apache module in that FastCGI PHP is an independent process. All PHP sub-processes are managed by a PHP-fpm component; while apache runs PHP in a modular mode, apache is responsible for calling PHP to complete the work. PHP's FastCGI method has much better performance than apache's modular method. Today we compile and install lamp in FastCGI mode.

Recommended reading:

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Compile and install LAMP in CentOS 5.9 (Apache 2.2.44 + MySQL 5.6.10 + PHP 5.4.12)

Source code for Web server architecture in RedHat 5.4 build the LAMP environment and application PHPWind

Build a WEB Server Linux + Apache + MySQL + PHP in the LAMP source code Environment

Ii. compiling environment and various software versions

The compiling environment and software versions are as follows:

Linux Web Server Php Mysql Xcache
CentOS 1, 6.4 Httpd-2.4.9 Php-5.4.26 Mysql-5.5.33-linux2.6-x86_64 Xcache-3.0.3

Xcache is a PHP Accelerator Used to improve PHP Execution efficiency.

3. Compile and install LAMP

1. Compile and install apache (refer to the previous article)

2. Compile and install mysql (refer to the previous article)

3. FastCGI installation of php

(1) Resolve Dependencies

Configure the yum source and run the following command:

# Yum-y groupinstall "Desktop Platform Development"

# Yum-y install bzip2-devel libmcrypt-devel

# Yum-y groupinstall "X Software Development"


To enable the compiled php to support mcrypt extensions, install the following software packages:

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.26

# Tar xf php-5.4.26.tar.bz2

# Cd php-5.4.26

#. /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


-- Enable-fpm: enables the php-fpm component to manage PHP

# Make

# Make intall

(4) Provide a configuration file for php. The configuration file is in the directory after the software is decompressed:

Cp php. ini-production/etc/php. ini

(5) Configure php-fpm to provide the SysV init script for php-fpm and add it to the service list:

# 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

(6) provide the configuration file for php-fpm:

# Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf


Edit the configuration file of php-fpm:

# Vim/usr/local/php/etc/php-fpm.conf

Configure fpm related options for your required values 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

(7), you can start php-fpm:

# Service php-fpm start


Run the following command to verify the running status (if the command output contains several php-fpm processes, the startup is successful ):

# Ps aux | 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:

# Netstat-tnlp | grep php-fpm

(8) Enable httpd 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:

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

(9) configure the VM to support fcgi. Add the following two lines to the corresponding VM.

ProxyRequests Off

ProxyPassMatch ^/(. * \. php) $ fcgi: // 127.0.0.1: 9000/PATH/TO/DOCUMENT_ROOT/$1

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.

For example, if the address you entered in the address bar is, l is changed:

DirectoryIndex index. php index.html

  • 1
  • 2
  • Next Page

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.