docker环境中安装gd扩展

Bertha 。 2023-07-12 11:51 53阅读 0赞
方案1

一般情况下可能会想到安装命令
docker-php-ext-install gd
但是很有可能出现错误
configure: error: png.h not found.
因为可能本身没有安装png等处理库

方案2
  1. #更新安装依赖资源库
  2. apt update
  3. #安装基础库
  4. apt install -y libwebp-dev libjpeg-dev libpng-dev libfreetype6-dev
  5. #设置配置文件
  6. 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 --with-ttf --enable-gd-native-ttf
  7. #安装扩展
  8. docker-php-ext-install gd
  9. #使扩展可用
  10. docker-php-ext-enable gd

安装过程中如果出现了以下错误,可能是apt的源设置的不正确
在这里插入图片描述
可以在/etc/apt/source.list中设置中科大的源再尝试上面的操作
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

备注:如果提示没有找到freetype-config,可以进行此如下操作自行编译稍微低一点的版本,由于 php-fpm 镜像使用的 libfreetype6 版本为 2.9.1-3 ,版本过新会导致 freetype-config 无法正常使用。解决方案
可以选择自行编译低版本的 freetype 2.8.1。
上代码。

  1. RUN apt-get update && \
  2. apt-get install -y --no-install-recommends \
  3. wget \
  4. && wget http://download.savannah.gnu.org/releases/freetype/freetype-2.8.1.tar.gz \
  5. && tar zxvf freetype-2.8.1.tar.gz \
  6. && cd freetype-2.8.1/ \
  7. && ./configure --prefix=/usr/include \
  8. && make && make install \
  9. && rm -rf ../freetype-2.8.1

发表评论

表情:
评论列表 (有 0 条评论,53人围观)

还没有评论,来说两句吧...

相关阅读