Skip to content

Install the PHP Imagick extension

The PHP Imagick extension allows PHP code to use the ImageMagick library for image processing.

The Imagick extension supports PHP 5.6 through PHP 8.2.

PHP 8.3+ is not yet supported by the Imagick extension. See the Imagick issue tracker for the status of Imagick’s PHP 8.3+ support.

Install the Imagick Extension

Installing the extension involves the following steps:

  1. Install build dependencies (packages that are required to build the extension).
  2. Build the extension’s library file.
  3. Enable the extension in the PHP configuration.

Install build dependencies

Set environment variables for the package manager.

Terminal window
export DEBIAN_FRONTEND=noninteractive

Install a compiler and other packages that are required for building PHP extensions.

Terminal window
sudo apt-get -y install gcc g++ make autoconf libc-dev pkg-config

Install additional packages that are required to build the Imagick extension.

Terminal window
sudo apt-get -y install libmagickwand-dev

Build the extension

The PECL install command compiles the extension’s .so library file.

Terminal window
yes '' | sudo pecl8.2-sp install imagick

Enable the extension

Configure PHP to load the extension.

Terminal window
sudo bash -c "echo extension=imagick.so > /etc/php8.2-sp/conf.d/imagick.ini"

Restart PHP-FPM.

Terminal window
sudo service php8.2-fpm-sp restart

Verify the extension is enabled in PHP.

Terminal window
php8.2-sp -i | grep imagick

If the extension is enabled, you will see output like the following.

/etc/phpX.Y-sp/conf.d/imagick.ini,
imagick
imagick module => enabled
imagick module version => 3.4.3RC1
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
Imagick compiled with ImageMagick version => ImageMagick 6.6.9-7 2016-06-01 Q16 http://www.imagemagick.org
Imagick using ImageMagick library version => ImageMagick 6.6.9-7 2016-06-01 Q16 http://www.imagemagick.org
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0

Uninstall the Imagick extension

Uninstalling the extension involves the following steps:

  1. Disable the extension in the PHP configuration.
  2. Remove the extension’s library file.

Disable the extension

Remove the extension’s configuration from PHP.

Terminal window
sudo rm /etc/php8.2-sp/conf.d/imagick.ini

Restart PHP-FPM.

Terminal window
sudo service php8.2-fpm-sp restart

Remove the extension

The PECL uninstall command removes the extension’s .so library file.

Terminal window
sudo pecl8.2-sp uninstall imagick

Using Imagick with PDF files

To allow ImageMagick to process PDF files, SSH into your server as root and edit the file:

/etc/ImageMagick-6/policy.xml

Locate the following line in the file:

/etc/ImageMagick-6/policy.xml
<policy domain="coder" rights="none" pattern="PDF" />;

Comment out this line by replacing it with the following:

/etc/ImageMagick-6/policy.xml
<!--<policy domain="coder" rights="none" pattern="PDF" />-->;

Finally, restart PHP.

Terminal window
sudo service php8.2-fpm-sp restart