Docker control example for php multi-version coexistence php-5.6 fpm service to run php test environment with host nginx

Because the default OpenSSL version of Ubuntu 18.04 is 1.1.0, and PHP 5.6 cannot be compiled under openssl 1.1 "PHP 5.6 is receiving only security fixes and OpenSSL 1.1 is not supported. Please use PHP 7.x if you want to use OpenSSL 1.1", so under Ubuntu 18.04, you need to configure the php5.6 environment through docker and the host.

The docker image series officially provided by PHP on docker hub has separate php, php packaged with apache, and php that provides fpm service, because the machine has installed nginx, so you only need to use docker to provide fpm service. 

Download and run

# 下载docker image
docker pull php:5-fpm
 
# 创建容器, 因为这里是本机开发环境, 使用默认的网络
docker run -d --name phpfpm -v /home/milton/somewhere/wwwroot:/var/www/html php:5-fpm
 
# 查看一下实际分配的IP地址
docker network inspect bridge
 
# 测试一下服务端口是否打开
telnet 172.17.0.2 9000

Modify local nginx configuration

Because the php-fpm service needs to be modified to be provided by docker, and the directory of the php file in docker is /var/www/html, and the original local use is /home/milton/somewhere/wwwroot, you need to modify the configuration file.

Original configuration

location ~ \.php$ {
        root           /home/milton/somewhere/wwwroot;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 
    location / {
        root   /home/milton/somewhere/wwwroot;
        index  index.html index.htm index.php;
    }
}

The two lines that need to be modified are fastcgi_pass and fastcgi_param, modified to

fastcgi_pass   172.17.0.2:9000;
fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

Write a phpinfo, restart nginx, and see if it can be parsed correctly.

Install necessary tools and extensions

The default php:5-fpm does not include tools such as ifconfig, ping, and some commonly used extensions, so you need to install it yourself

# 进入docker命令行
docker exec -it phpfpm /bin/bash
 
# 安装 ifconfig, ping
apt update
apt install net-tools iputils-ping
 
# 安装依赖(安装gd扩展等必须要先安装系统依赖)
apt install libfreetype6-dev libmcrypt-dev libpng-dev libjpeg-dev libpng-dev sendmail zlib1g-dev

Install the extension with docker-php-ext-install, this script will automatically compile and configure the specified extension

docker-php-ext-install mysql
docker-php-ext-install gd
docker-php-ext-install zip
docker-php-ext-install mbstring
docker-php-ext-install pdo_mysql

After restarting docker, refresh the phpinfo page to see if it takes effect.

If you are installing the pecl extension, this image already has pecl, run the pecl command directly, pay attention to specify the version, so as not to be incompatible with the current PHP version

If you want to install mongo or other extensions, you need to install libssl-dev. To enter the content, you need apt install openssh libssl-dev

If there is a problem with reading php and nginx files, you can set open_base of php.ini to handle it

pecl install redis-4.0.1
# 中途提示选no, 因为需要额外的.h文件支持, 没安装而选yes的话会设置失败
enable igbinary serializer support? [no] :
enable lzf compression support? [no] :
# 启用
docker-php-ext-enable redis

docker network

Because the default bridge where docker is located, IP: 172.17.0.x can directly access the host and the external network. In subsequent use, the host's services will be accessed through the host's external IP instead of 127.0.0.1 .

Guess you like

Origin blog.csdn.net/oqzuser12345678999q/article/details/108482631