Use Docker to run multiple PHP versions on the server

Use Docker to run multiple PHP versions on the server

PHP7 has been out for quite some time, and it is well known that it has greatly improved performance. Now suppose we have an older server with a centos6 system, on which some old projects are running, and the default php version is 5.3.

Although we can upgrade to PHP7 version, the old version is not compatible with PHP7, so we cannot make a one-size-fits-all approach. The best way is for php5.3 and php7 to coexist. Therefore, we can consider using docker to install other versions of PHP, which can ensure the independence of the environment and cause little performance loss.

The following takes the installation of PHP7 version as an example to introduce the specific steps.

Install docker on centos6:

yum install -y https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm
 service docker start
 chkconfig docker on

Pull the php7.2 image

docker pull php:7.2-fpm

Create a new directory and file /usr/local/docker-php7/zz-docker.conf and save the following content:

[global]
daemonize = no
[www]
listen = 9001

;To modify the variables in php.ini, just modify the corresponding attributes of the php_value array

php_value[session.save_handler] = redis
php_value[session.save_path] = tcp://127.0.0.1:6379
php_value[post_max_size] = 20M
php_value[upload_max_filesize] = 20M
php_value[date.timezone] = Asia/Shanghai
php_value[opcache.enable] = 1
php_value[opcache.enable_cli] = 1

Run the container and use host mode to communicate with the host

docker run -d -v /var/www/html:/var/www/html -v /usr/local/docker-php7/zz-docker.conf:/usr/local/etc/php-fpm.d/zz-docker.conf --net=host --name php7.2 php:7.2-fpm

Install various common PHP extensions

docker exec php7.2 apt-get update -y
docker exec php7.2 apt-get install -y libfreetype6-dev
docker exec php7.2 apt-get install -y libjpeg62-turbo-dev
docker exec php7.2 apt-get install -y libpng-dev
docker exec php7.2 docker-php-ext-install pdo_mysql
docker exec php7.2 docker-php-ext-install mysqli
docker exec php7.2 docker-php-ext-install iconv 
docker exec php7.2 docker-php-ext-install gd
docker exec php7.2 docker-php-ext-install mbstring
docker exec php7.2 docker-php-ext-install opcache
#By the way, change the configuration docker exec php7.2 mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini

Since the redis extension cannot be installed through docker-php-ext-install , you need to install it manually.

#Enter the command line in the container docker exec -it php7.2 sh 
docker-php-source extract
curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/4.2.0.tar.gz
tar -zxvf /tmp/redis.tar.gz -C /usr/src/php/ext
mv /usr/src/php/ext/phpredis-* /usr/src/php/ext/phpredis
docker-php-ext-install phpredis
#Press ctr+p and ctrl+q here to exit the container docker restart php7.2

The above command has successfully run php7.2 on port 9001. Next, just point the PHP script to port 9001 in the nginx configuration (it originally pointed to port 9000)

Summarize

The above is what I introduced to you about using docker to run multiple php versions on the server. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • How to run postgreSQL with docker
  • How to run MySQL using docker-compose
  • How to dynamically add a volume to a running Docker container
  • K3s Getting Started Guide - Detailed Tutorial on Running K3s in Docker

<<:  Analysis of the principle of Vue nextTick

>>:  Detailed steps for installing the decompressed version of MySQL 5.7.20 (two methods)

Recommend

The implementation process of Linux process network traffic statistics

Preface Linux has corresponding open source tools...

How to install phabricator using Docker

I am using the Ubuntu 16.04 system here. Installa...

Detailed explanation of sshd service and service management commands under Linux

sshd SSH is the abbreviation of Secure Shell, whi...

JavaScript imitates Jingdong magnifying glass special effects

This article shares the specific code of JavaScri...

A brief analysis of Vue's asynchronous update of DOM

Table of contents The principle of Vue asynchrono...

Solution to forgetting MySQL root password in MACOS

MySQL is a relational database management system ...

Detailed explanation of JavaScript function this pointing problem

Table of contents 1. The direction of this in the...

An example of how to quickly deploy web applications using Tomcat in Docker

After learning the basic operations of Docker, we...

Detailed explanation of MySQL backup process using Xtrabackup

Table of contents 01 Background 02 Introduction 0...

Vue defines private filters and basic usage

The methods and concepts of private filters and g...