I'm unable to install imagick. I'm always running into this error:
checking ImageMagick MagickWand API configuration program... configure: error: not found. Please
provide a path to MagickWand-config or Wand-config program.
I've tried all solutions I could find on google, but without any success. Hope to have some luck here. These are the steps I've taken:
RUN apt-get update && apt-get install -y imagemagick php5-imagick libpng-dev libmagickwand-dev
libmagickcore-dev && \
curl -L http://pecl.php.net/get/imagick-3.1.1.tgz >> /usr/src/php/ext/imagick.tgz && \
tar -xf /usr/src/php/ext/imagick.tgz -C /usr/src/php/ext/ && \
rm /usr/src/php/ext/imagick.tgzRUN docker-php-ext-install imagick-3.1.2
http://stackoverflow.com/q/14332539/433558 appears to be a report of this exact issue, and the solution in http://stackoverflow.com/a/14354912/433558 is working for me (ie, using pecl install imagick-beta instead of pecl install imagick):
FROM php:5
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN pecl install imagick-beta
That seems to solve it. Thanks!
Somehow the extension is not loaded though.
only if I do it this way:
RUN apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* && \
curl -L https://pecl.php.net/get/imagick-3.3.0RC2.tgz >> /usr/src/php/ext/imagick.tgz && \
tar -xf /usr/src/php/ext/imagick.tgz -C /usr/src/php/ext/ && \
rm /usr/src/php/ext/imagick.tgz
RUN docker-php-ext-install imagick-3.3.0RC2
I've added imagick.so to the php.ini file, but that didn't seem to work.
Does docker-php-ext-install do something extra besides creating a .ini file?
Yes, that would be https://github.com/docker-library/php/blob/ae130b2f845162fbf84da0ffad07d7a64eff57cd/docker-php-ext-install#L44-L57 (which isn't perfect, but it works OK).
So, you probably just need to add something like this:
RUN echo 'extension=rmagick.so' > /usr/local/etc/php/conf.d/ext-rmagick.ini
I've contemplated adding a docker-php-ext-enable, but I'm not sure whether that'd really be useful since it's essentially just that one-liner. Perhaps our docs section about how to use docker-php-ext-install should be followed by a section about how to use PECL appropriately instead. :+1:
:+1:
I had troubles getting this to work. In the end I found the following snipplet used by a Wordpress Dockerfile that did work.
RUN apt-get update && apt-get install -y libmagickwand-6.q16-dev --no-install-recommends \
&& ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/MagickWand-config /usr/bin \
&& pecl install imagick \
&& echo "extension=imagick.so" > /usr/local/etc/php/conf.d/ext-imagick.ini
If this could be abstracted away into am docker-php-ext-install imagemagick that would be awesome! Not sure how the mechanism works though.
It's worth pointing out here that https://github.com/docker-library/php/pull/122 did add docker-php-ext-enable and that imagick has been updated, so I've just tested the following Dockerfile to be working successfully:
FROM php:5
RUN apt-get update && apt-get install -y libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN pecl install imagick && docker-php-ext-enable imagick
root@f1a53d21c435:/# php -i | grep magic
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-imagick.ini
libmagic => 517
imagick
imagick module => enabled
imagick module version => 3.3.0
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 6.8.9-9 Q16 x86_64 2015-01-05 http://www.imagemagick.org
Imagick using ImageMagick library version => ImageMagick 6.8.9-9 Q16 x86_64 2015-01-05 http://www.imagemagick.org
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0
Is installing imagick on PHP 7 not possible?
7.0.0
FROM php:7.0.0-fpm
# Install Imagick.
RUN apt-get-update && apt-get install -y \
libmagickwand-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick
---> Running in 793875575c01
pecl/imagick is not compatible with PHP version 7.0.0
No valid packages found
install failed
Removing intermediate container 793875575c01
7.0.3
FROM php:7.0.3-fpm
# Install Imagick.
RUN apt-get-update && apt-get install -y \
libmagickwand-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick
Step 5 : RUN pecl install imagick
---> Running in ee9f8c037810
pecl/imagick requires PHP (version >= 5.1.3, version <= 7.0.0, excluded versions: 7.0.0), installed version is 7.0.3
No valid packages found
install failed
Removing intermediate container ee9f8c037810
@AustinMaddox, that looks like an issue with imagick itself; they don't yet support php7 in their releases, but there is a branch in their code that would work, but I am not sure how stable it is since it is not yet in a regular release. The branch is here https://github.com/mkoppanen/imagick/tree/phpseven and it looks like there is info on installing it in https://github.com/mkoppanen/imagick/issues/129. There is an RC6 release.
There's a 3.4.1 release of imagick now which seems to work fine with PHP7. I was able to install it with
FROM php:7.0.3-fpm
RUN apt-get update \
&& apt-get -y install \
libmagickwand-dev \
--no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& rm -r /var/lib/apt/lists/*
I'm trying this on Alpine Linux and it doesn't work 😢
FROM php:7.0-fpm-alpine
RUN apk add --update imagemagick-dev \
&& pecl install imagick \
&& docker-php-ext-enable imagick
Have you a solution for Alpine Linux ?
@fgirardey, did you also apk add --no-cache any other dependencies? The alpine variant is kept extremely minimal, so you would need to add in any tools like autoconf or a C compiler. I think the full set you would need is:
$ apk add --no-cache autoconf gcc g++ imagemagick-dev libtool make
To save final image space, you should also be able to remove most of them in the same RUN once the extension is compiled.
@yosifkit it absolutely solved my problem 😊
my finale image is like that :
FROM php:7.0-fpm-alpine
MAINTAINER Florian GIRARDEY <[email protected]>
RUN apk add --update freetype-dev libpng-dev libjpeg-turbo-dev libxml2-dev autoconf g++ imagemagick-dev libtool make \
&& docker-php-ext-install gd \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& docker-php-ext-install soap \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& apk del autoconf g++ libtool make \
&& rm -rf /tmp/* /var/cache/apk/*
@fgirardey You want to run docker-php-ext-install gd _after_ you ran docker-php-ext-configure gd ….
@franz-josef-kaiser Oh yeah you are right, it wasn't working.
Now it seems to be better, thanks a lot :
FROM php:7.0-fpm-alpine
MAINTAINER Florian GIRARDEY <[email protected]>
# install the PHP extensions we need
RUN apk add --update freetype-dev libpng-dev libjpeg-turbo-dev libxml2-dev autoconf g++ imagemagick-dev libtool make \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& docker-php-ext-install soap \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& apk del autoconf g++ libtool make \
&& rm -rf /tmp/* /var/cache/apk/*
I use this way to install imagick for php:5 and other solution not work for me!
FROM php:5.6-apache
MAINTAINER Ali Mihandoost <[email protected]>
COPY . /var/www/html/
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y php5-imagick --no-install-recommends \
&& php5enmod imagick
&& rm -rf /var/lib/apt/lists/*
@AliMD, I am hesitant to recommend that way, since the php5-imagick package from Debian may not work with the version of PHP that the container has.
I would highly recommend against using Debian-packaged PHP bits with this image -- we don't provide the bits dpkg needs to know which version of PHP we've included, so it will likely end up pulling in Debian's php packages (which will either shadow the PHP we've installed or be ignored due to ours taking precedence).
I've just tested the following for installing imagick with php:5.6-apache successfully:
FROM php:5.6-apache
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install imagick-3.4.1 \
&& docker-php-ext-enable imagick
And again, with Alpine and PHP 7, for good measure:
FROM php:7-alpine
RUN set -x \
&& apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS imagemagick-dev libtool \
&& pecl install imagick-3.4.1 \
&& docker-php-ext-enable imagick \
&& apk add --no-cache --virtual .imagick-runtime-deps imagemagick \
&& apk del .phpize-deps
Closing, given that the original issue appears to be fully resolved.
ProTip: Remember to export PHP's CFLAGS/CPPFLAGS/LDFLAGS before installing imagick-3.4.1
&& export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
Otherwise improved ASLR and optimizations are not taken in count by the extension and therefore makes hardened PHP less safer than it should be.
@pwnsdx Better press Y when you want to link to some file. This gives you the exact commit as reference – else you are linking to a maybe moving target.
@franz-josef-kaiser Noted :)
For PHP 7.1 you need imagick-3.4.3.
https://bugs.php.net/bug.php?id=72311
FROM php:7.1-fpm-alpine
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
Same as above comment (PHP 7.1 you need imagick-3.4.3) but for debian based Dockerfile. I took tianon (Tianon Gravi)'s solution with pwnsdx (Sabri)'s pro tip for improved ASLR and optimizations in a single layer:
FROM php:7.1-fpm
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install imagick-3.4.3 \
&& docker-php-ext-enable imagick
🚀
Its works for me too ... on php 7.2
FROM php:7.2-fpm
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install imagick-3.4.3 \
&& docker-php-ext-enable imagick
Can confirm @heygrady solution worked for me on php:7.2-alpine3.8.
alpine3.8 php 7.0 7.1 tested
https://gist.github.com/ptflp/5cc7ff386ed3338bac4033ec13c339e9
Has anyone experience with php:7.2-apache
I tried the following
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install imagick-3.4.3 \
&& docker-php-ext-enable imagick
It seems that it was installed:
php -i | grep imagick
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-imagick.ini,
imagick
imagick module => enabled
imagick module version => 3.4.3
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0
But when I type "which convert" e.g nothing returns.
If you want the convert command (which is not a PHP command nor is it even related to PHP), you need to install a package which provides it. In Debian Stretch, that's graphicsmagick-imagemagick-compat or imagemagick-6.q16 (as can be seen on https://packages.debian.org/stretch/imagemagick).
I ran into some problems trying to install Imagick to a CircleCI container. Specifically, a cryptic Exited with code 141 error:

The solution was to ignore the error with || true.
In total, installation looks like this:
sudo apt-get update
sudo apt-get install -y libmagickwand-dev --no-install-recommends
yes '' | sudo pecl install imagick || true
sudo docker-php-ext-enable imagick
This solution works like a charm for PHP5.
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/* \
&& pecl install imagick-3.3.0 \
&& docker-php-ext-enable imagick
However, the image build fails when I try to target a specific Imagick beta version (3.2.0RC1, I am trying to reproduce as faithfully as possible our production environment). It would seem like the MagickWand is not compatible (?):
checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
ERROR: /tmp/pear/temp/imagick/configure --with-php-config=/usr/local/bin/php-config --with-imagick' failed
The command '/bin/sh -c export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" && apt-get update && apt-get install -y --no-install-recommends libmagickwand-6.q16-dev && rm -rf /var/lib/apt/lists/* && pecl install imagick-3.2.0RC1 && docker-php-ext-enable imagick' returned a non-zero code: 1
#Install imagemagick:
ENV MAGICK_HOME=/usr
RUN apk --no-cache update \
&& apk --no-cache upgrade \
&& apk add --update freetype-dev libpng-dev libjpeg-turbo-dev libxml2-dev autoconf g++ imagemagick-dev imagemagick libtool make \
&& docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& docker-php-ext-install soap \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& apk del autoconf g++ libtool make
Best solution php 7.3
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 +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions imagick
Putting all together, even avoiding the interactive shell of "autodetect" :
FROM php:7.2-fpm
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
libmagickwand-dev \
&& rm -rf /var/lib/apt/lists/* \
&& yes '' | pecl install imagick-3.4.3|| true \
&& docker-php-ext-enable imagick
But still it does not work. May be my case is different : I have supervisord is the main process (PID 1) and there is no php-fpm is runnning... because the role of this container is to be queue worker only (php artisan queue:work ).
I am not sure which should i restart to make it work ?
OR should I hit php-fpm to start fpm process ? or no need ?
UPDATE :
Also you need to install gs or ghostscripts if you are converting from PDF to images.
wget https://github.com/luvvien/resources/raw/master/ghostscript-9.22-linux-x86_64.tar.gz \
&& tar -xzvf ghostscript-9.22-linux-x86_64.tar.gz \
&& cd ghostscript-9.22-linux-x86_64 \
&& cp gs-922-linux-x86_64 /usr/local/bin/gs \
&& ln -s /usr/local/bin/gs /usr/bin/gs \
&& rm ../ghostscript-9.22-linux-x86_64.tar.gz \
&& rm -rf ghostscript-9.22-linux-x86_64
@abdennour did you try install-php-extensions?
No @mlocati ! what's this ?
@abdennour see the above comment https://github.com/docker-library/php/issues/105#issuecomment-565352897
@abdennour He was referring to this script here: docker-php-ext-install.
_Note: Link points to current latest blob on the master branch._
Edit: I missed the link that @mlocati posted to his extension installer above. He was referring to that one.
Most helpful comment
I would highly recommend against using Debian-packaged PHP bits with this image -- we don't provide the bits
dpkgneeds to know which version of PHP we've included, so it will likely end up pulling in Debian'sphppackages (which will either shadow the PHP we've installed or be ignored due to ours taking precedence).I've just tested the following for installing
imagickwithphp:5.6-apachesuccessfully:And again, with Alpine and PHP 7, for good measure: