This article mainly introduces how to set multi-version PHP coexistence in Linux and use Nginx servers. it relies on the php-fpm tool for management. For more information, see
Application Environment
In the LNMP environment, the current PHP version is 5.3.8. When an application needs to support only PHP 5.2.x, it also hopes to keep the existing application still using PHP 5.3.8. That is to say, two versions of PHP must exist at the same time for nginx to call different versions as needed.
Ideas
Nginx interacts with PHP through PHP-FastCGI. After PHP-FastCGI runs, it will listen through files or local ports. configuring the corresponding FastCGI listening port or file in Nginx will explain Nginx requests to PHP.
Since PHP-FastCGI listens to ports and files, different versions of PHP-FastCGI can run simultaneously and listen to different ports or files, in Nginx, you can call different PHP-FastCGI ports or files as needed to achieve PHP coexistence in different versions.
Configuration Record
The following is a simple configuration process, based on the debian environment with lnmp installed. The current version of PHP is 5.3.8 in/usr/local/php.
1. download the PHP-5.2.14 and related FPM, autoconf components:
mkdir ~/php5.2cd ~/php5.2wget -c http://museum.php.net/php5/php-5.2.14.tar.gzwget -c http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
2. unzip the PHP-5.2.14 and patch the PHP-FPM:
tar zxvf php-5.2.14.tar.gzgzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
3. if you have been installed through lnmp, you should have installed autoconf, if not, please download and compile the autoconf-2.13, and then set the autoconf environment variables:
export PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf¬export PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
3. compile the installation PHP-5.2.14 under the new path (/usr/local/php-5.2.14), note the path-prefix,-with-config-file-path, and open 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=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fastcgi --enable-fpmmake ZEND_EXTRA_LIBS='-liconv'make install
4. set/usr/local/php-5.2.14/etc/php-fpm.conf, listening port:
127.0.0.1:9001
Or listen to the file:
/path/to/unix/socket
Other parameters are customized based on the server environment and requirements.
5. start php-fpm and manage it later through php-fpm:
/usr/local/php-5.2.14/sbin/php-fpm start
After php5.3.3, php has inherited php-fpm to php, and the built-in php-fpm does not support smooth start parameters (start | stop | reload) by default, you need to use the startup script control provided in the official source code:
cp -f (php -5.3.x-source-dir)/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod 755 /etc/init.d/php-fpm/etc/init.d/php-fpm start
Operations supported by php-fpm:
- Start to start the FastCGI process of PHP.
- Stop: force the FastCGI process of PHP to terminate.
- Quit: smoothly terminate the FastCGI process of PHP.
- Restart: restart the FastCGI process of PHP.
- Reload: reload PHP. ini.
- Logrotate to re-enable log files.
5.3.3 operations supported by the php-fpm script: start | stop | force-quit | restart | reload | status
6. configure the php. ini of the PHP-5.2.14 and reload it 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 nginx configuration, use PHP-5.2.14 for the desired service configuration:
location ~ .*.(php|php5)?$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; include fcgi.conf; }
8. record the configuration used for compiling 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-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