New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install imagick #105

Closed
boedy opened this Issue Jun 8, 2015 · 29 comments

Comments

Projects
None yet
@boedy
Copy link

boedy commented Jun 8, 2015

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.tgz

RUN docker-php-ext-install imagick-3.1.2

@tianon

This comment has been minimized.

Copy link
Member

tianon commented Jun 12, 2015

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
@boedy

This comment has been minimized.

Copy link

boedy commented Jun 14, 2015

That seems to solve it. Thanks!

@boedy boedy closed this Jun 14, 2015

@boedy

This comment has been minimized.

Copy link

boedy commented Jun 14, 2015

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?

@boedy boedy reopened this Jun 14, 2015

@tianon

This comment has been minimized.

Copy link
Member

tianon commented Jun 19, 2015

Yes, that would be

ini="/usr/local/etc/php/conf.d/docker-php-ext-$ext.ini"
for module in modules/*.so; do
if [ -f "$module" ]; then
if grep -q zend_extension_entry "$module"; then
# https://wiki.php.net/internals/extensions#loading_zend_extensions
line="zend_extension=$(basename "$module")"
else
line="extension=$(basename "$module")"
fi
if ! grep -q "$line" "$ini" 2>/dev/null; then
echo "$line" >> "$ini"
fi
fi
done
(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. 👍

@boedy

This comment has been minimized.

Copy link

boedy commented Jun 22, 2015

👍

@roelvanduijnhoven

This comment has been minimized.

Copy link

roelvanduijnhoven commented Aug 10, 2015

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.

@tianon

This comment has been minimized.

Copy link
Member

tianon commented Jan 18, 2016

It's worth pointing out here that #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
@AustinMaddox

This comment has been minimized.

Copy link

AustinMaddox commented Feb 12, 2016

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
@yosifkit

This comment has been minimized.

Copy link
Member

yosifkit commented Feb 12, 2016

@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 mkoppanen/imagick#129. There is an RC6 release.

@mikehaertl

This comment has been minimized.

Copy link

mikehaertl commented Mar 14, 2016

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/*
@fgirardey

This comment has been minimized.

Copy link

fgirardey commented Jun 30, 2016

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 ?

@yosifkit

This comment has been minimized.

Copy link
Member

yosifkit commented Jun 30, 2016

@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.

@fgirardey

This comment has been minimized.

Copy link

fgirardey commented Jul 4, 2016

@yosifkit it absolutely solved my problem 😊

my finale image is like that :

FROM php:7.0-fpm-alpine

MAINTAINER Florian GIRARDEY <fgirardey@groupeforum.pro>

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/*
@franz-josef-kaiser

This comment has been minimized.

Copy link

franz-josef-kaiser commented Jul 24, 2016

@fgirardey You want to run docker-php-ext-install gd after you ran docker-php-ext-configure gd ….

@fgirardey

This comment has been minimized.

Copy link

fgirardey commented Aug 5, 2016

@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 <fgirardey@groupeforum.pro>

# 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/*
@AliMD

This comment has been minimized.

Copy link

AliMD commented Sep 26, 2016

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 <i@ali.md> 

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/*
@yosifkit

This comment has been minimized.

Copy link
Member

yosifkit commented Sep 26, 2016

@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.

@tianon

This comment has been minimized.

Copy link
Member

tianon commented Sep 26, 2016

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
@tianon

This comment has been minimized.

Copy link
Member

tianon commented Sep 26, 2016

Closing, given that the original issue appears to be fully resolved.

@pwnsdx

This comment has been minimized.

Copy link

pwnsdx commented Feb 7, 2017

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.

@franz-josef-kaiser

This comment has been minimized.

Copy link

franz-josef-kaiser commented Feb 8, 2017

@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.

@pwnsdx

This comment has been minimized.

Copy link

pwnsdx commented Feb 8, 2017

@franz-josef-kaiser Noted :)

@heygrady

This comment has been minimized.

Copy link

heygrady commented Mar 17, 2017

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

bkmagnetron added a commit to bkmagnetron/docker-php-apache that referenced this issue Jun 1, 2017

@GabLeRoux

This comment has been minimized.

Copy link

GabLeRoux commented Nov 30, 2017

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

🚀

@felipemarques

This comment has been minimized.

Copy link

felipemarques commented Sep 13, 2018

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
@bensquire

This comment has been minimized.

Copy link

bensquire commented Oct 24, 2018

Can confirm @heygrady solution worked for me on php:7.2-alpine3.8.

@ptflp

This comment has been minimized.

Copy link

ptflp commented Dec 12, 2018

@fischkopp

This comment has been minimized.

Copy link

fischkopp commented Jan 11, 2019

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.

@tianon

This comment has been minimized.

Copy link
Member

tianon commented Jan 12, 2019

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).

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