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

Introduction to the role of HTML doctype

Document mode has the following two functions: 1. ...

jQuery achieves large-screen scrolling playback effect

This article shares the specific code of jQuery t...

Detailed steps for deploying Microsoft Sql Server with Docker

Table of contents 1 Background 2 Create a contain...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

Detailed Explanation of JavaScript Framework Design Patterns

Table of contents mvc mvp mvvm The source of Vue ...

Summary of some HTML code writing style suggestions

Omit the protocol of the resource file It is reco...

Linux cut command explained

The cut command in Linux and Unix is ​​used to cu...

Practical notes on installing Jenkins with docker-compose

Create a Directory cd /usr/local/docker/ mkdir je...

Hover zoom effect made with CSS3

Result:Implementation code: html <link href=&#...

Summary of pitfalls in importing ova files into vmware

Source of the problem As we all know, all network...

100-1% of the content on the website is navigation

Website, (100-1)% of the content is navigation 1....

Detailed explanation of the execution process of JavaScript engine V8

Table of contents 1. V8 Source 2. V8 Service Targ...