Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker php 7.1 imagick

Tags:

php

docker

Docker php 7.1 imagick:-

pecl install imagick \
&& docker-php-ext-enable imagick \
  • No releases available for package "pecl.php.net/imagick" install failed

  • ERROR: Service 'app' failed to build

like image 902
William Avatar asked Nov 13 '17 06:11

William


People also ask

How do I enable Imagick PHP?

To enable Imagick for your website, go to your Site Tools -> Dev -> PHP Manager. Click the PHP Extensions tab and find the entry for the “imagick” extension in the list that appears. Then click the Change value button (pencil icon), select the On radio button for Status and save the changes.

How do I install Imagick Docker?

run: sudo apt-get install -y php7-imagick. sudo aptitude -y install imagemagick. sudo aptitude -y install libmagickcore-dev. After the installation, enable Imagick on the hosting account by heading to file Manager under Site in the Site Tools section.


2 Answers

From the official docker image docs:

"E: Package 'php-XXX' has no installation candidate"

As of docker-library/php#542, this image blocks the installation of Debian's PHP packages. There is some additional discussion of this change in docker-library/php#551 (comment), but the gist is that installing Debian's PHP packages in this image leads to two conflicting installations of PHP in a single image, which is almost certainly not the intended outcome.

For those broken by this change and looking for a workaround to apply in the meantime while a proper fix is developed, adding the following simple line to your Dockerfile should remove the block (with the strong caveat that this will allow the installation of a second installation of PHP, which is definitely not what you're looking for unless you really know what you're doing):

RUN rm /etc/apt/preferences.d/no-debian-php

The proper solution to this error is to either use FROM debian:XXX and install Debian's PHP packages directly, or to use docker-php-ext-install, pecl, and/or phpize to install the necessary additional extensions and utilities.

The Solution

Dockerfile:

FROM php:7.1

RUN apt update && \
    apt upgrade && \
    apt install -y libmagickwand-dev --no-install-recommends && \
    pecl install imagick && docker-php-ext-enable imagick && \
    rm -rf /var/lib/apt/lists/*

Build it with:

$ sudo docker build -t exadra37/php-imagick:7.1 .

... some output ommitted ....

s/no-debug-non-zts-20160303/imagick.so

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/imagick.so'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
Removing intermediate container 71902c85c47a
 ---> 8142e9efd5ea
Successfully built 8142e9efd5ea
Successfully tagged exadra37/php-imagick:7.1

Checking it is installed:

$ sudo docker run --rm -it exadra37/php-imagick:7.1 bash
root@012656fef3a0:/# php -i | grep -ir 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 compiled with ImageMagick version => ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Imagick using ImageMagick library version => ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0
root@012656fef3a0:/# 
like image 199
Exadra37 Avatar answered Oct 29 '22 07:10

Exadra37


The answer from @Exadra37 is correct. But please note that you can also remove some APT packages after the installation of the PHP extension (they are needed only to compile/install the extension, not to use it - you'll save almost 200 MB):

FROM php:7.1

RUN apt-get update && \
    apt-get install -y libmagickwand-dev && \
    pecl install imagick && \
    docker-php-ext-enable imagick && \
    apt-get remove --purge -y automake autotools-dev bzip2-doc fontconfig gir1.2-freedesktop gir1.2-gdkpixbuf-2.0 gir1.2-glib-2.0 gir1.2-rsvg-2.0 icu-devtools javascript-common libblkid-dev libbz2-dev libcairo-gobject2 libcairo-script-interpreter2 libcairo2 libcairo2-dev libcroco3 libdatrie1 libdjvulibre-dev libdjvulibre-text libdjvulibre21 libelf1 libexif-dev libexif-doc libexif12 libexpat1-dev libffi-dev libfontconfig1-dev libfreetype6-dev libfribidi0 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-bin libgdk-pixbuf2.0-common libgdk-pixbuf2.0-dev libgirepository-1.0-1 libglib2.0-bin libglib2.0-data libglib2.0-dev libglib2.0-dev-bin libgraphite2-3 libharfbuzz0b libice-dev libice6 libicu-dev libilmbase-dev libilmbase23 libjbig-dev libjpeg-dev libjpeg62-turbo-dev libjs-jquery libjxr-tools libjxr0 liblcms2-dev liblqr-1-0-dev libltdl-dev liblzma-dev liblzo2-2 libmagickcore-6-arch-config libmagickcore-6-headers libmagickcore-6.q16-6-extra libmagickcore-6.q16-dev libmagickwand-6-headers libmagickwand-6.q16-dev libmagickwand-dev libmount-dev libmpdec2 libopenexr-dev libopenexr23 libopenjp2-7-dev libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpixman-1-0 libpixman-1-dev libpng-dev libpng-tools libpthread-stubs0-dev libpython3-stdlib libpython3.7-minimal libpython3.7-stdlib libreadline7 librsvg2-2 librsvg2-common librsvg2-dev libselinux1-dev libsepol1-dev libsm-dev libsm6 libthai-data libthai0 libtiff-dev libtiffxx5 libtool libwmf-dev libwmf0.2-7 libx11-dev libxau-dev libxcb-render0 libxcb-render0-dev libxcb-shm0 libxcb-shm0-dev libxcb1-dev libxdmcp-dev libxext-dev libxml2-dev libxrender-dev libxrender1 libxt-dev libxt6 mime-support python3 python3-distutils python3-lib2to3 python3-minimal python3.7 python3.7-minimal readline-common shared-mime-info uuid-dev x11-common x11proto-core-dev x11proto-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev zlib1g-dev && \
    rm -rf /var/lib/apt/lists/*

Managing the list of required APT packages may be a mess, so I developer a script to do that. You can simply write something like this:

FROM php:7.1

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

RUN install-php-extensions imagick

This install-php-extensions script supports the PHP extensions listed here

like image 30
Michele Locati Avatar answered Oct 29 '22 06:10

Michele Locati