Skip to content

Instantly share code, notes, and snippets.

@johndatserakis
Last active August 5, 2024 06:22
Show Gist options
  • Save johndatserakis/825a16a7f3cef4e8b4dbfbb1e80b9f9c to your computer and use it in GitHub Desktop.
Save johndatserakis/825a16a7f3cef4e8b4dbfbb1e80b9f9c to your computer and use it in GitHub Desktop.
Install imagick In Docker FROM php:7.1-fpm-alpine

docker-library/php#105

RUN set -ex \
    && apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \
    && export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
    && pecl install imagick-3.4.3 \
    && docker-php-ext-enable imagick \
    && apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
    && apk del .phpize-deps
@mlocati
Copy link

mlocati commented Dec 13, 2019

Just a side note: I recently added Alpine support to my install-php-extensions script: you can easily install the imagick PHP extension (as well as many other extensions) on Alpine & Debian by running:

ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions imagick

@peter279k
Copy link

To install and build the imagemagick extension, the Dockerfile contents are as follows:

FROM php:7.1-fpm-alpine

RUN set -ex && \
        apk add --no-cache --virtual .build-deps \
        libxml2-dev \
        shadow \
        autoconf \
        g++ \
        make \
    && apk add --no-cache imagemagick-dev imagemagick libjpeg-turbo libgomp freetype-dev \
    && pecl install imagick \
    && docker-php-ext-enable imagick \
    && apk del .build-deps
CMD ["php-fpm"]

@Server4001
Copy link

Super helpful. Thank you.

I found that uninstalling gcc broke imagick with PHP Warning: PHP Startup: Unable to load dynamic library 'imagick' though.

I ended up using this:

# Needed by phpize and imagick. These can be removed. Same thing as 'imagemagick-dev $PHPIZE_DEPS', but without gcc
apk add --no-cache --virtual .build-deps imagemagick-dev autoconf dpkg-dev file g++ libc-dev make pkgconf re2c
# Needed by phpize and imagick. Cannot remove these.
apk add --no-cache imagemagick gcc
printf "\n" | pecl install imagick
docker-php-ext-enable imagick
php -v
php -m
apk del .build-deps

@mlocati
Copy link

mlocati commented Aug 5, 2024

I found that uninstalling gcc broke imagick

I don't think imagick needs gcc. I think the problem is that when you uninstall gcc, apk will also uninstall other system libraries that are required by imagick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment