Linux nginx Multi-version PHP coexistence

Source: Internet
Author: User
Tags diff

Application environment


LNMP environment, the current PHP version 5.3.8, encountered an application need only support PHP 5.2.x, but also want to keep existing applications or PHP 5.3.8. This means that two versions of PHP are required to be present at the same time for Nginx to invoke different versions as needed.


Ideas


Nginx interacts with PHP via php-fastcgi. And php-fastcgi run will be through the file, or the local port two ways to listen, in Nginx configuration of the corresponding fastcgi listening port or file is to implement Nginx request for PHP interpretation.


Since php-fastcgi is listening port and file, it can let different versions of php-fastcgi run simultaneously, listen to different ports or files, Nginx in accordance with the requirements of the configuration call different php-fastcgi port or file, you can achieve different versions of PHP coexistence.


Configuration Records


The following document is a simple configuration process based on the Debian environment where LNMP is already installed. The current version of PHP is 5.3.8, located in/usr/local/php.


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


Help

1

2

3

4

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. Unzip the PHP-5.2.14 and hit the PHP-FPM patch:


Help

1

2

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 installed through LNMP, you should have installed autoconf, if not, please download and compile the autoconf-2.13 yourself, then set the AUTOCONF environment variable:


Help

1

2

Export php_autoconf=/usr/local/autoconf-2.13/bin/autoconf?

Export Php_autoheader=/usr/local/autoconf-2.13/bin/autoheader

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


Help

1

2

3

4

5

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=/usr/ Local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-fastcgi--enable-fpm

Make zend_extra_libs= '-liconv '

Make install

4. Set/usr/local/php-5.2.14/etc/php-fpm.conf, listening port:


Help

1

<value name= "Listen_address" >127.0.0.1:9001</value>

Or listen to the file:

Help

1

<value name= "Listen_address" >/path/to/unix/socket</value>

Additional parameters are customized to the server environment and requirements.

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


Help

1

/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) The smooth start parameters, you need to use the official source code provided in the boot script to control:

Help

1

2

3

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

Operations supported by PHP-FPM:


Start, launch the PHP fastcgi process.

Stop, forcing the PHP fastcgi process to terminate.

Quit, smooth termination of PHP fastcgi process.

Restart, restart the PHP fastcgi process.

Reload, reload PHP php.ini.

Logrotate, re-enable the log file.

Operations 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 effective:


Help

1

2

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 to use PHP-5.2.14 for the required service configuration:


Help

1

2

3

4

5

6

Location ~. *. (PHP|PHP5)? $

{

Fastcgi_pass 127.0.0.1:9001;

Fastcgi_index index.php;

Include fcgi.conf;

}

8. Record the configuration you used to compile php5.5.10


Help

1

./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-GD-- 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--with-mcrypt=/usr/bin --enable-zip--enable-soap--enable-mbstring--with-gd--with-openssl--enable-pcntl--with-xmlrpc--enable-opcache

Resources:


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

Posted in Linux, PHP | 1 Response


Linux nginx Multi-version PHP coexistence

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.