最新消息:走过的,离开的,已经错过,新开始2016

果果.it 笔记-docker安装PHP镜像整合NGINX+MySQL

技术随笔 果果 1679浏览 0评论

扔在草稿箱里面两个月了,一直没时间写完,截图都不知道扔哪了去了。。。

今天我们继续来我们NGINX+PHP+MySQL最后一项,安装PHP。

docker pull php:7.3-fpm

一开始安装的是7.2,国内仓库一直失败,后换成7.3。

docker images

docker run --name php73 -p 9000:9000 -v /home/nginx/html:/var/www/html -d php:7.3-fpm

有一个错误,是因为DNS的原因,后面果果解决了不能解析的问题。请记住这里的/var/www/html 路径。

在nginx的配置文件里面加入

location ~ \.php {
root html;
fastcgi_pass 172.17.0.4:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}

查看php容器的内部IP

docker inspect --format='{{.NetworkSettings.IPAddress}}' php73

把IP写到 fastcgi_pass中。

fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;

其中的/var/www/html/ 为我们刚才创建容器的时候映射的路径。

保存配置重启nginx镜像。

在站点目录下面,新建一个PHP文件测试。

浏览器访问,nginx我们在上篇已经映射了8062端口。

下面我们来给PHP安装一个pdo_mysql和gd扩展。

我们先进入PHP容器。

docker exec -it php73 /bin/bash
/usr/local/bin/php -m

可以看到已经安装的扩展。

直接执行

docker-php-ext-install pdo_mysql gd

我们可以看到pdo_mysql 成功,而gd的编译报错了。

checking for FreeType 2... no
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-webp-dir=<DIR>
If configure fails try --with-jpeg-dir=<DIR>
configure: error: png.h not found.

是因为缺少依赖。

apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev

可是果果一路安装依赖包下去,最后还是卡住在这里。

The following packages have unmet dependencies:
zlib1g-dev : Depends: zlib1g (= 1:1.2.8.dfsg-2+b1) but 1:1.2.8.dfsg-5 is to be installed
E: Unable to correct problems, you have held broken packages.

我们需要更换一个源,之前使用的阿里云源不行,我们更换中科大源。

果果.it 笔记-docker容器配置的修改与挂载修改源。

deb http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian stable main contrib non-free
deb http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian stable-proposed-updates main contrib non-free
//更新软件源
apt update
//安装各种库
apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
//解压源码
docker-php-source extract
//进入gd源码文件夹
cd /usr/src/php/ext/gd
//准备编译
docker-php-ext-configure gd --with-webp-dir=/usr/include/webp --with-jpeg-dir=/usr/include --with-png-dir=/usr/include --with-freetype-dir=/usr/include/freetype2
//编译安装
docker-php-ext-install gd
//查看是否成功安装gd扩展
php -m | grep gd

退出容器,并重启容器。

docker restart php73

查看PHPinfo是否已经加载已经安装的扩展。

到这里我们docker的PHP的基础教程基本已经完结了,其他扩展可以参考官方文档和上面介绍的方法安装。

转载请注明:果果.IT » 果果.it 笔记-docker安装PHP镜像整合NGINX+MySQL

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址