Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Adding imagick to my docker LAMP I got error :You should add “extension=imagick.so” to php.ini

Hello, Adding imagick to my docker LAMP installation I got error

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20180731/imagick.so'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
/bin/sh: 1: imagick: not found
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update &&     apt-get install -y     python     libfreetype6-dev     libwebp-dev     libjpeg62-turbo-dev     libpng-dev     libzip-dev     nano     mc     git-core     libmagickwand-dev --no-install-recommends &&     pecl install imagick && imagick &&     docker-php-ext-enable imagick &&     curl     build-essential     openssl     libssl-dev     libgmp-dev     libldap2-dev     netcat     locate     && git clone https://github.com/nodejs/node.git     && cd node     && git checkout v12.0.0     && ./configure      && make      && make install' returned a non-zero code: 127

In Dockerfile.yml I added lines for imagick :

FROM php:7.3-apache

RUN apt-get update && \
    apt-get install -y \
    python \
    libfreetype6-dev \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libzip-dev \
    nano \
    mc \
    git-core \

    # I added these lines
    libmagickwand-dev --no-install-recommends && \
    pecl install imagick && imagick && \
    docker-php-ext-enable imagick && \

    curl \
    build-essential \
    openssl \
    libssl-dev \
    libgmp-dev \
    libldap2-dev \
    netcat \
    locate \
    # composer \
    && git clone https://github.com/nodejs/node.git \
    && cd node \
    && git checkout v12.0.0 \
    && ./configure \
     && make \
     && make install

  RUN npm install cross-env

  RUN  docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/


  # Install Composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

  RUN  docker-php-ext-install gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif  \
&& a2enmod rewrite

  # I added this line
  RUN install-php-extensions imagick

COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

Which options did I miss ?

0 likes
7 replies
MaverickChan's avatar

how did you install apache2 and php?

please always do : sudo apt update

before you install any app then sudo apt install your-app

if you have a fresh new linux system you can sudo apt install apache2 php

remember after installed php , you have to manually install some php extensions after all these then sudo apt install imagick

actually , linux is smart enough to add config to your server and php.ini

Sinnbeck's avatar

Try this instead (instead of that one line)

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
mstdmstd's avatar

I am not sure which must be modifications. I modified my Dockerfile.yml as :

FROM php:7.3-apache

RUN apt-get update && \
    apt-get install -y \
    python \
    libfreetype6-dev \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libzip-dev \
    nano \
    mc \
    git-core \

   # I LEFT THESE 3 LINES
   libmagickwand-dev --no-install-recommends && \
   pecl install imagick && imagick && \
   docker-php-ext-enable imagick && \

    curl \
    build-essential \
    openssl \
    libssl-dev \
    libgmp-dev \
    libldap2-dev \
    netcat \
    locate \
    # composer \
    && git clone https://github.com/nodejs/node.git \
    && cd node \
    && git checkout v12.0.0 \
    && ./configure \
     && make \
     && make install

  RUN npm install cross-env

  RUN  docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/


  # Install Composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

  RUN  docker-php-ext-install gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif  \
&& a2enmod rewrite

  # THESE 2 LINES ADDES

    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
    
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

But I got error anyway :

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20180731/imagick.so'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
/bin/sh: 1: imagick: not found
ERROR: Service 'web' failed to build: 

?

Sinnbeck's avatar

You might need to use one of the php.ini files as well

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
mstdmstd's avatar

I modified docker file:

  ...

  RUN  docker-php-ext-install gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif  \
&& a2enmod rewrite

  # ADDED THIS LINE

    RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

    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
  
    
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

but got error :

Build process completed successfully
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20180731/imagick.so'
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h'
install ok: channel://pecl.php.net/imagick-3.4.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=imagick.so" to php.ini
/bin/sh: 1: imagick: not found
ERROR: Service 'web' failed to build:
Sinnbeck's avatar

Ok then try adding it manually

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

RUN echo "extension=imagick.so" >> "$PHP_INI_DIR/php.ini" \
mstdmstd's avatar

I added the line in /Dockerfile.yml :

  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

  RUN  docker-php-ext-install gd pdo pdo_mysql zip gmp bcmath pcntl ldap sysvmsg exif  \
&& a2enmod rewrite


    RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

    RUN echo "extension=imagick.so" >> "$PHP_INI_DIR/php.ini" \

    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
  
    
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf

and still got error :

Build process completed successfully 
Installing '/usr/local/lib/php/extensions/no-debug-non-zts-20180731/imagick.so' 
Installing '/usr/local/include/php/ext/imagick/php_imagick_shared.h' 
install ok: channel://pecl.php.net/imagick-3.4.4 
configuration option "php_ini" is not set to php.ini location 
You should add "extension=imagick.so" to php.ini 
/bin/sh: 1: imagick: not found 
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update &&     apt-get install -y     python     libfreetype6-dev     libwebp-dev     libjpeg62-turbo-dev     libpng-dev     lib
zip-dev     nano     mc     git-core  

Also I have virtualhost.conf included, with content :

<VirtualHost *:80>

  DocumentRoot /var/www/vanilla_crm_docker_root/public
  <Directory /var/www/vanilla_crm_docker_root/public>
    Order allow,deny
    Allow from all

    Options -MultiViews

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ / [L,R=301]


	php_value  memory_limit  2048M
	php_value  file_uploads  On
	php_value  upload_max_filesize  200M
	php_value  post_max_size  200M
	php_value  max_execution_time  1000
	php_value  short_open_tag  On


    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
  </Directory>

  ErrorLog /var/log/apache2/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

</VirtualHost>
  1. can it be that this file overwrites “extension=imagick.so” option we prepare in our command?
  2. Can I add extension=imagick.so option in this file ?

Please or to participate in this conversation.