Home >Backend Development >PHP Tutorial >Set up multiple versions of PHP to coexist in Linux system and use it with Nginx server, _PHP tutorial

Set up multiple versions of PHP to coexist in Linux system and use it with Nginx server, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:32737browse

Set up multiple versions of PHP to coexist in the Linux system and use it with the Nginx server,

Application environment

In the LNMP environment, the current PHP version is 5.3.8. When I encounter an application requirement that only supports PHP 5.2.x, I want to keep the existing application or use PHP 5.3.8. In other words, two versions of PHP need to exist at the same time for nginx to call different versions as needed.

Thoughts

Nginx interacts with PHP through PHP-FastCGI. After PHP-FastCGI is run, it will listen through files or local ports. Configuring the corresponding FastCGI listening port or file in Nginx will allow Nginx to request the interpretation of PHP.

Since PHP-FastCGI listens to ports and files, different versions of PHP-FastCGI can be run at the same time and listen to different ports or files. Nginx can be configured to call different PHP-FastCGI ports or files according to requirements, that is Different versions of PHP can coexist.

Configuration record

The simple configuration process is recorded below, based on the Debian environment where lnmp has been installed. The current version of PHP is 5.3.8, located in /usr/local/php.

1. Download PHP-5.2.14 and related FPM and 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. Unzip PHP-5.2.14 and apply PHP-FPM 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 installed through lnmp, autoconf should have been installed. If not, please download and compile autoconf-2.13 yourself, and then set the 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 and install PHP-5.2.14 in the new path (/usr/local/php-5.2.14), pay attention to the paths of –prefix and –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-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 monitor file:

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

Other parameters can be customized according to the server environment and needs.
5. Start php-fpm, which can be managed through php-fpm in the future:

/usr/local/php-5.2.14/sbin/php-fpm start

After php5.3.3, php has inherited php-fpm into php, and the built-in php-fpm does not support the (start|stop|reload) smooth startup parameters by default. You need to use the startup provided in the official source code. 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

Operations supported by php-fpm:

  • start, starts PHP’s FastCGI process.
  • stop, forcefully terminate the PHP FastCGI process.
  • quit, smoothly terminates PHP's FastCGI process.
  • restart, restart PHP’s FastCGI process.
  • reload, reload PHP's php.ini.
  • logrotate, re-enable the log file.

Operations supported by the php-fpm script of 5.3.3: start|stop|force-quit|restart|reload|status

6. Configure the php.ini of 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 the nginx configuration and use PHP-5.2.14 for the required service configuration:

location ~ .*.(php|php5)&#63;$
    {
      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
./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

Articles you may be interested in:

  • Detailed implementation of PHP multi-version coexistence solution connected to Apache under CentOS

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084577.htmlTechArticle Set up multiple versions of PHP to coexist in the Linux system and use it with the Nginx server. The application environment is LNMP environment. The current PHP version is 5.3. 8. I encountered an application requirement that only supports PHP 5.2.x and wanted to keep it current...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn