3

I'm trying to install imagick on alpine linux for php8.2 and I don't really understand how to do it. I see that the imagick extension is still in testing. From what I read I can install it by specifying a different repository. However when I do so, I get an error: php82-common (no such package):. I can't find what this package php82-common is.

My dockerfile is as follows:

FROM laravelphp/vapor:php82

RUN apk --update add postgresql14-client

# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'

# INSTALL PHP EXTENSIONS
RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing
RUN apk --update add imagemagick imagemagick-dev
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install gd
RUN docker-php-ext-install exif

# Place application in Lambda application directory...
COPY . /var/task
Carl Wirkus
  • 523
  • 1
  • 8
  • 19

3 Answers3

1

Bellow one is working for me for php:8.2-fpm-alpine

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS imagemagick-dev \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& apk del .build-deps
0

The reason that the php82-pecl-imagick package is not found is that it graduated from Alpine's testing repository to community. Therefore, the community repository should be passed to apk's --repository option:

RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community

In addition, you are missing the pecl command for installing the Imagick PHP extension:

RUN pecl install imagick

Here's the fixed Dockerfile, that builds successfully:

FROM laravelphp/vapor:php82

RUN apk --update add postgresql14-client

# INSTALL COMPOSER
RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'

# INSTALL PHP EXTENSIONS
RUN apk add php82-pecl-imagick --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk --update add imagemagick imagemagick-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install gd
RUN docker-php-ext-install exif

# Place application in Lambda application directory...
COPY . /var/task

For reference, you can find the image build output here.

valiano
  • 16,433
  • 7
  • 64
  • 79
0

Easily install PHP extensions in Docker containers: special plugin

Also don't forget install Imagick to your system, in my case - Alpine Linux.

Full checked instructions for Docker file with Imagick OPCache Memcached and Redis (choose your plugins from official github page with the table there, here all plugins for Wordpress site as example):

FROM php:fpm-alpine
RUN apk update && apk add imagemagick ghostscript-fonts ghostscript
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions opcache imagick memcached redis ssh2 sockets bcmath exif intl zip mysqli
COPY php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
COPY php/php.ini $PHP_INI_DIR/php.ini

It must work very well! Some adds... Create folder 'php' and add there a opcache.ini on your own config. Also add php.ini, configurate it on your own way.