Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set up the coexistence of multiple versions of PHP in Linux system to cooperate with Nginx server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Xiaobian to share with you how to set up multi-version PHP coexistence in Linux system with Nginx server use, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it together!

application environment

LNMP environment, the current PHP version 5.3.8, encountered an application requirements only support PHP 5.2.x, and want to keep the existing application or PHP 5.3.8. This means that two versions of PHP need to exist at the same time, so that nginx can call different versions as needed.

ideas

Nginx interacts with PHP via PHP-FastCGI. After PHP-FastCGI runs, it will listen in two ways: file or local port. Configure the corresponding FastCGI listening port or file in Nginx to realize Nginx request interpretation of PHP.

Since PHP-FastCGI is listening to ports and files, you can let different versions of PHP-FastCGI run at the same time, listening to different ports or files, Nginx calls different PHP-FastCGI ports or files according to the requirements configuration, you can achieve different versions of PHP coexistence.

configuration record

The following documents a simple configuration flow, based on a debian environment with lnmp installed. The current version of PHP is 5.3.8 and is located in/usr/local/php.

1. Download 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 PHP-5.2.14 and patch it with 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 installed it via lnmp, you should have autoconf installed. If not, 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 Under the new path (/usr/local/php-5.2.14), note the paths-prefix, -with-config-file-path, and turn on 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, listen port:

127.0.0.1:9001

Or listen to files:

/path/to/unix/socket

Other parameters are customized according to the server environment and requirements.

5. Start php-fpm and manage it later via php-fpm:

/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 (start) by default.| stop| reload), you need to use the startup script provided in the official source code to control:

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

php-fpm supports:

start, start PHP FastCGI process.

stop: Forcefully terminates PHP's FastCGI process.

quit, smoothly terminating PHP's FastCGI process.

restart, restart PHP FastCGI process.

reload, reload PHP php.ini.

logrotate, re-enable log files.

5.3.3 php-fpm script supported operations: start| stop| force-quit| restart| reload| status

6. Configure 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, 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. Note the configuration you used to compile php 5.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 How to set up multi-version PHP coexistence with Nginx server in Linux system "All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report