Linux nginx Multiple versions of PHP coexistence __linux

Source: Internet
Author: User
Tags diff fpm
Application Environment

LNMP environment, the current PHP version 5.3.8, encountered an application requirements to support only PHP 5.2.x, but also want to maintain the existing application or PHP 5.3.8. That is, two versions of PHP are required to exist simultaneously, for Nginx to invoke different versions as needed. train of Thought

Nginx is interacting with PHP through php-fastcgi. and php-fastcgi after running through the file, or the local port two ways to monitor, in Nginx configure the corresponding fastcgi listening port or file that is to achieve Nginx request to PHP interpretation.

Since php-fastcgi is listening on ports and files, you can allow different versions of php-fastcgi to run at the same time, listening to different ports or files, Nginx in accordance with the requirements of the configuration call different php-fastcgi ports or files, can be implemented in different versions of PHP coexistence. Configuration Records

A simple configuration process is documented below, based on the Debian environment that has been installed LNMP. The current version of PHP is 5.3.8, located in/usr/local/php.

1. Download PHP-5.2.14 and related FPM, autoconf components:

mkdir ~/php5.2
cd ~/php5.2
wget-c http://museum.php.net/php5/php-5.2.14.tar.gz wget-c http://
Php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz

2. Extract the PHP-5.2.14 and php-fpm the patch:

Tar zxvf php-5.2.14.tar.gz
gzip-cd php-5.2.14-fpm-0.5.14.diff.gz | patch-d php-5.2.14-p1

3. If you have already installed through the LNMP, should already have the autoconf, if not, please download and compile autoconf-2.13, then set autoconf environment variable:

Export php_autoconf=/usr/local/autoconf-2.13/bin/autoconf¬
Export php_autoheader=/usr/local/autoconf-2.13/ Bin/autoheader

3. Compile installation PHP-5.2.14 under the new Path (/usr/local/php-5.2.14), note the –prefix, –with-config-file-path Path, and open the fastcgi and FPM options:

CD php-5.2.14/
./buildconf--force
./configure--prefix=/usr/local/php-5.2.14--with-config-file-path=/usr /local/php-5.2.14/etc--with-mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-fpm make
ZEND_ extra_libs= '-liconv ' make
Install
4. Set/usr/local/php-5.2.14/etc/php-fpm.conf, listening port:
<value name= "Listen_address" >127.0.0.1:9001</value>
or listening to files:
<value name= "Listen_address" >/path/to/unix/socket</value>
Other parameters are customized according to the server environment and requirements.

5. Start PHP-FPM, later can be managed by PHP-FPM:

/USR/LOCAL/PHP-5.2.14/SBIN/PHP-FPM start
After the word php5.3.3, PHP has inherited php-fpm into PHP, and the built-in PHP-FPM default does not support (start|stop|reload) Smooth boot parameters, you need to use the official source code to provide the boot script to control:

Cp-f (php-5.3.x-source-dir)/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
chmod 755/etc/init.d/php-fpm
/etc /INIT.D/PHP-FPM start

PHP-FPM supported operations: Start, start the PHP fastcgi process. Stop, forcing the end of PHP's fastcgi process. Quit, smooth end of PHP fastcgi process. Restart, restart PHP's fastcgi process. Reload, Reload PHP's php.ini. Logrotate, re-enable log files.

Actions supported by the 5.3.3 PHP-FPM script: Start|stop|force-quit|restart|reload|status

6. Configure the PHP-5.2.14 php.ini, reload to take effect:

Vi/usr/local/php-5.2.14/etc/php.ini
/usr/local/php-5.2.14/sbin/php-fpm Reload
7. Modify the Nginx configuration and use PHP-5.2.14 for the required service configuration:
Location ~. *.            (PHP|PHP5) $
{
Fastcgi_pass 127.0.0.1:9001;
Fastcgi_index index.php;
Include fcgi.conf;
}
8. Make a note of the configuration you used to compile php5.5.10
./configure--prefix=/usr/local/php-5.5.10--with-config-file-path=/usr/local/php-5.5.10/etc--with-mysql=mysqlnd --with-mysqli=mysqlnd--with-bz2--with-curl=/usr/bin--enable-ftp--enable-sockets--disable-ipv6-- With-jpeg-dir=/usr/local--with-png-dir=/usr/local--with-freetype-dir=/usr/local--enable-gd-native-ttf-- With-iconv-dir=/usr/local--enable-mbstring--enable-calendar--with-gettext--with-libxml-dir=/usr/local-- With-zlib--with-pdo-mysql=mysqlnd--enable-dom--enable-xml--enable-fpm--with-libdir=lib64 --enable-zip--enable-soap--enable-mbstring--with-gd--with-openssl--enable-pcntl--with-xmlrpc--enable-opcache

reference materials: http://ixdba.blog.51cto.com/2895551/806622 Http://www.yinfor.com/blog/archives/2008/05/install_zend_optimizer_ 33_on_c.html http://ideas.spkcn.com/technology/php-technology/133.html http://zhangxugg-163-com.iteye.com/blog/ 1894990

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.