PHP教程

Docker Nginx1.21 + PHP7.4 部署

本文主要是介绍Docker Nginx1.21 + PHP7.4 部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1、PHP7.4 容器配置

#1. 启动PHP7.4
docker run --restart=always --name myphp-docker -v ~/nginx/www:/www -d php:7.4-fpm

#2.登录PHP7.4容器
docker exec -it myphp-docker bash

#3.更新APT仓库 先做备份:
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb http://mirrors.163.com/debian/ stretch main non-free contrib" >/etc/apt/sources.list
echo "deb http://mirrors.163.com/debian/ stretch-proposed-updates main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ stretch main non-free contrib" >>/etc/apt/sources.list
echo "deb-src http://mirrors.163.com/debian/ stretch-proposed-updates main non-free contrib" >>/etc/apt/sources.list

#4.更新软件源
apt update

#5.安装各种库
apt-get install --allow-downgrades -y  zlib1g=1:1.2.8.dfsg-5 zlib1g-dev libz-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev libjpeg-dev

#6.解压源码
docker-php-source extract

#7.进入gd源码文件夹
cd /usr/src/php/ext/gd

#8.准备编译
docker-php-ext-configure gd --with-webp=/usr/include/webp --with-jpeg=/usr/include  --with-freetype=/usr/include/freetype2

#9.编译安装 
docker-php-ext-install -j$(nproc) gd

#10.安装其他需要的PHP组件
docker-php-ext-install pdo_mysql mysqli mbstring

#11.检查扩展是否安装成功
php -m | grep gd
#12.退出php容器终端
exit
#13.重启php容器
……

2、Nginx容器配置

docker run --restart=always --name nginx-php -p 8080:80 -p 8090-8099:8090-8099 -d \
    -v ~/nginx/www/:/usr/share/nginx/html:ro \
    -v ~/nginx/conf/conf.d:/etc/nginx/conf.d:ro \
    --link myphp-docker:php \
    nginx:1.21

 

这篇关于Docker Nginx1.21 + PHP7.4 部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!