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

Some small methods commonly used in html pages

Add in the <Head> tag <meta http-equiv=&q...

How to avoid the trap of URL time zone in MySQL

Preface Recently, when using MySQL 6.0.x or highe...

Examples of using html unordered list tags and ordered list tags

1. Upper and lower list tags: <dl>..</dl...

Summary of the differences between global objects in nodejs and browsers

In Node.js, a .js file is a complete scope (modul...

The principle and application of MySQL connection query

Overview One of the most powerful features of MyS...

Detailed tutorial on installing pxc cluster with docker

Table of contents Preface Preliminary preparation...

Linux lossless expansion method

Overview The cloud platform customer's server...

Will the deprecated Docker be replaced by Podman?

The Kubernetes team recently announced that it wi...

Detailed explanation of the marquee attribute in HTML

This tag is not part of HTML3.2 and is only suppo...

A brief discussion on creating cluster in nodejs

Table of contents cluster Cluster Details Events ...