当我尝试将
imagick
php 扩展添加到我的 Docker 映像时,使用 PHP 时出现错误。
FROM php:8.2-fpm-alpine
RUN apk add --update --no-cache --virtual .build-deps $PHPIZE_DEPS imagemagick imagemagick-dev libgomp \
&& pecl install imagick \
&& echo 'extension=imagick.so;' >> $PHP_INI_DIR/conf.d/imagick.ini \
&& rm -rf /tmp/pear \
&& apk del .build-deps
Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imagick.so (Error loading shared library libgomp.so.1: No such file or directory (needed by /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imagick.so)), /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imagick.so.so (Error loading shared library /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imagick.so.so: No such file or directory)) in Unknown on line 0
我该如何解决这个问题?
您将库安装为构建依赖项,然后将其删除:
apk add --update --virtual .build-deps ... imagemagick imagemagick-dev libgomp
apk del .build-deps
你想要这样的东西:
RUN apk add <...> imagemagick imagemagick-dev libgomp \
&& apk add <...> --virtual .build-deps $PHPIZE_DEPS \
&& pecl install imagick \
&& echo 'extension=imagick.so;' >> $PHP_INI_DIR/conf.d/imagick.ini \
&& rm -rf /tmp/pear \
&& apk del .build-deps
构建工具(如 gcc)是开发依赖项,但库本身是运行时依赖项。