← ServerPilot Docs

How to Install the PHP IMagick Extension

All PHP versions installed by ServerPilot include the GD extension. GD is PHP's officially supported image processing.

WordPress and most other applications can use either GD or IMagick for image processing, so installing IMagick is generally not required.

The IMagick extension allows PHP code to use the ImageMagick library.

The IMagick extension supports:

  • PHP 8.0, 8.1, and 8.2
  • PHP 7.0, 7.1, 7.2, 7.3, and 7.4
  • PHP 5.6

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

Install the IMagick Extension

In the commands shown, replace "X.Y" with your app's PHP version (for example, "7.4" or "8.2").
To install a PECL extension for multiple PHP versions, repeat the PECL extension installation for each PHP version.

The IMagick extension is a PHP extension for creating and modifying images using a PHP interface to the ImageMagick library.

To install this extension, run the following commands as your server's root user:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmagickwand-dev
yes '' | sudo peclX.Y-sp install imagick

Once installed, create a configuration file for the extension and restart PHP by running the following commands as root:

sudo bash -c "echo extension=imagick.so > /etc/phpX.Y-sp/conf.d/imagick.ini"
sudo service phpX.Y-fpm-sp restart

Verify the IMagick Installation

You can verify the ImageMagick extension is installed with this command:

phpX.Y-sp -i | grep imagick

If ImageMagick is installed correctly, you will see 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 ImageMagick Extension

To uninstall this extension, as root run the commands:

sudo rm /etc/phpX.Y-sp/conf.d/imagick.ini
sudo peclX.Y-sp uninstall imagick

Next, restart PHP-FPM with the command:

sudo service phpX.Y-fpm-sp restart

Using Imagick with PDF Files

ImageMagick was not designed to securely handle untrusted PDF files. Enabling PDF file handling as shown below is dangerous if any malicious PDF files are ever processed.

Additionally, attempting to work around ImageMagick's PDF security issues by using Ghostscript directly is also dangerous as Ghostscript is also vulnerable to exploitation when processing malicious PDF files.

In order to allow ImageMagick to process PDF files, you must SSH into your server as root and edit the following file:

/etc/ImageMagick-6/policy.xml

Locate the line:

<policy domain="coder" rights="none" pattern="PDF" />

Comment out this line by replacing it with the following:

<!--<policy domain="coder" rights="none" pattern="PDF" />-->

Finally, restart PHP:

sudo service phpX.Y-fpm-sp restart
Last updated: October 28, 2024

Launch your first site in 5 minutes