Docker + PHP:8.1.1-FPM 如何安装 imagick php 扩展?

问题描述 投票:0回答:2

尝试安装适用于 php 8.1.1 的 imagick。

在我的

Dockerfile
下面的
composer install
图像上出现以下错误:

Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - Root composer.json requires PHP extension ext-imagick ^3.6 but it is missing from your system. Install or enable PHP's imagick extension.

To enable extensions, verify that they are enabled in your .ini files:
    - 
    - /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-calendar.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-gd.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-xsl.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini

我尝试了各种解决方案

apt install php-imagick
给出错误:

Package php-imagick is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

apt install php8.1-imagick
没有找到任何包裹

在我的

RUN docker-php-ext-install php-imagick
末尾添加
RUN docker-php-ext-install imagick
Dockerfile
没有找到任何包裹

Dockerfile

FROM php:8.1.1-fpm

RUN apt-get clean && apt-get update \
    &&  apt-get install -y --no-install-recommends \
        locales \
        apt-utils \
        git \
        libicu-dev \
        g++ \
        libpng-dev \
        libxml2-dev \
        libzip-dev \
        libonig-dev \
        libxslt-dev \
        unzip \
        libpq-dev \
        nodejs \
        npm \
        wget \
        apt-transport-https \
        lsb-release \
        ca-certificates

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen  \
    &&  locale-gen

RUN curl -sS https://getcomposer.org/installer | php -- \
    &&  mv composer.phar /usr/local/bin/composer

RUN curl -sS https://get.symfony.com/cli/installer | bash \
    &&  mv /root/.symfony/bin/symfony /usr/local/bin

RUN docker-php-ext-configure \
            intl \
    &&  docker-php-ext-install \
            pdo pdo_mysql pdo_pgsql opcache intl zip calendar dom mbstring gd xsl

RUN pecl install apcu && docker-php-ext-enable apcu

RUN npm install --global yarn

WORKDIR /var/www/app/

RUN apt-get install -y libmagickwand-dev
RUN apt-get install -y imagemagick
RUN pecl install imagick

COPY ./app/composer.json ./
COPY ./app/composer.lock ./
php docker imagick
2个回答
34
投票

要安装

Imagick
PHP 扩展和库,我们需要修改 Dockerfile。

示例如下,首先我们更新系统源和包,然后获取 PHP 扩展运行所需的包。之后我们使用

pecl
安装它,最后告诉 docker 在
PHP Extensions
列表上启用它。

RUN apt-get update; \
    apt-get install -y libmagickwand-dev; \
    pecl install imagick; \
    docker-php-ext-enable imagick;

旁注:如果您是 bash 新手,想知道为什么它没有一堆 RUN 命令而只有一个命令。

\
只是将它们链接到下一行。


0
投票

安装完所有内容后我仍然无法解决这个问题。 “docker-php-ext-enable imagick”显示未找到命令,并且错误“Call to undefined function Intervention\Image\Drivers\Gd\Decoders\imagecreatefromjpeg()”仍然存在

© www.soinside.com 2019 - 2024. All rights reserved.