Docker环境下基于Alpine文件系统给php7.4安装GD库
直接上代码给急着用的同学。在Dockerfile加上这句或者在容器里面运行这句指令:
apk add \
freetype \
freetype-dev \
libpng \
libpng-dev \
libjpeg-turbo \
libjpeg-turbo-dev \
&& docker-php-ext-configure gd \
--with-webp --with-jpeg --with-jpeg=/usr/include --with-freetype=/usr/include/freetype2/ \
&& docker-php-ext-install -j$(nproc) gd特别注意php7.4的之后编译GD库的指令有了一些变更,可以在官方看到Changes about
官方截图:

更改如下:
- --with-gd 改变为 --enable-gd (whether to enable the extension at all) 和 --with-external-gd (to opt into using an external libgd, rather than the bundled one).
- --with-png-dir 参数被移除。需要 libpng 支持。
- --with-zlib-dir 参数被移除。需要 zlib 支持。
- --with-freetype-dir 改变为 --with-freetype
- --with-jpeg-dir 改变为 --with-jpeg
- --with-webp-dir 改变为 --with-webp
- --with-xpm-dir 改变为 --with-xpm
所以我们不能再用之前的指令来编译了,只要跟着改一下指令即可。