Solution for coexistence of multiple versions of PHP under Linux system (super simple)

Solution for coexistence of multiple versions of PHP under Linux system (super simple)

Since PHP7 came out, as a fan of the latest version, I immediately upgraded to experience it. However, since there are still old programs running on the server, I had to deploy a PHP multi-version coexistence environment.

The existing environment is lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8

In order to better compatibility with old PHP programs, it is recommended to use 5.4.45. It is mainly compatible with MySQL extension.

Start Installation

First, download the php-5.4.45.tar.gz source package.

Install from source

# tar xzvf php-5.4.45.tar.gz
# cd php-5.4.45

# ./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-intl --with-xsl

# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-production /usr/local/php/etc/php.ini

php.ini configuration

post_max_size = 50M
upload_max_filesize = 50M
date.timezone = PRC
short_open_tag = On
cgi.fix_pathinfo=0
max_execution_time = 300
disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

php-fpm.conf configuration

# vim /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php54/var/run/php-fpm.pid
error_log = /usr/local/php54/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php54-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1:9001
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 40
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 40
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

Note: The key is to configure the listening port and process

Start php-fpm

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm
# chmod +x /etc/init.d/php54-fpm
# /etc/init.d/php54-fpm start

Modify the nginx configuration and use php-5.4.45 for the required service configuration

location ~ [^/]\.php(/|$)
 {
  try_files $uri =404;
  fastcgi_pass unix:/tmp/php54-cgi.sock;
  fastcgi_index index.php;
  include fastcgi.conf;
 }

Configure php54-fpm of php-5.4.45 to start automatically at boot

# chkconfig --add php54-fpm
# chkconfig php54-fpm on

chkconfig Function Description: Check and set various system services.
Syntax: chkconfig [–add][–del][–list][system service]
chkconfig [–level <level code>][system service][on/off/reset]

The focus of this program is

Each PHP version should be installed in a new separate folder

Each PHP version's php-fpm.conf configuration file needs to set a different process name and listening port

The PHP version listening port or process name to be used is specified in the nginx configuration file

You may also be interested in:
  • How to execute Linux commands in PHP
  • How to install redis in php7 under Linux
  • How to build phpmyadmin in Linux based on php-fpm mode lamp
  • Install multiple versions of PHP for Nginx on Linux
  • PHP website server security configuration reinforcement protection method under Linux [recommended]
  • Tutorial on migrating mysql from phpstudy to Linux
  • Install the latest PHP7 on VMware Linux system

<<:  Detailed explanation of the limitations and restrictions of MySQL partitioned tables

>>:  MySQL Optimization: InnoDB Optimization

Recommend

Mysql sorting to get ranking example code

The code looks like this: SELECT @i:=@i+1 rowNum,...

How to implement the builder pattern in Javascript

Overview The builder pattern is a relatively simp...

Two ways to connect WeChat mini program to Tencent Maps

I've been writing a WeChat applet recently an...

About the correct way to convert time in js when importing excel

Table of contents 1. Basics 2. Problem Descriptio...

MySQL 5.6 binary installation process under Linux

1.1 Download the binary installation package wget...

Press Enter to automatically submit the form. Unexpected discovery

Copy code The code is as follows: <!DOCTYPE ht...

Summary of Linux user groups and permissions

User Groups In Linux, every user must belong to a...

How to manage cached pages in Vue

Table of contents Problem 1: Destruction 1. How t...

How to enable JMX monitoring through Tomcat

Build a simulation environment: Operating system:...

HTML code to add icons to transparent input box

I was recently writing a lawyer recommendation we...

Adobe Brackets simple use graphic tutorial

Adobe Brackets is an open source, simple and powe...

Detailed explanation of Vue save automatic formatting line break

I searched for many ways to change it online but ...