How to: Install ImageMagick from source on Ubuntu 14.04

The ImageMagick version available in package managers is often quite out of date, so if you want to use a recent version you often have to install it from source.

It's worth noting that this isn't something to do lightly as once you have installed ImageMagick from source you are then responsible for keeping it updated. It won't be upgraded by doing an apt-get update && apt-get upgrade.

Check the version of ImageMagick available

So the first thing to check is the version of ImageMagick that's available, to determine whether you actually need to install from source. This can be done by running the following command:

apt-cache policy imagemagick

That should output the version available for installation. At the time of writing and running this command on an AWS EC2 instance the version available was 6.7.7.10, which was the latest version back in June 2012 according to the changelog.

Installing ImageMagick from source

When running "checkinstall" I accepted all the defaults (keep pressing the enter key).

apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xzvf ImageMagick.tar.gz
ls
cd ImageMagick<version number here>/
./configure
make clean
make
checkinstall
ldconfig /usr/local/lib

To check ImageMagick has installed properly

convert -version

Uninstalling

As we used "checkinstall" we can cleanly uninstall ImageMagick in the future using the following command (changing the version number to match that installed):

dpkg -r imagemagick-6.9.0

Installing ImageMagick PHP Module

Unfortunately, when installing the ImageMagick PHP Module via "apt-get install php5-imagick" this seems to install a seperate "imagick-common" package, which still uses the 6.7.7.10 version rather than the newer version we've just installed (thanks to Stijn Huyberechts for pointing this out).

Therefore, we have to install the PHP module manually and the process differs slightly depending on the version of PHP we're running (5 or 7).

Manually installing the ImageMagick PHP Module for PHP5 (see below for PHP7)

Please note: In order to run "phpize" you may need to first install "php5-dev" so run "apt-get install php5-dev".

First, we need to identify the version number of the latest stable version of the module from the PECL repository, then update the steps below with that version number (at the time of writing that is 3.3.0):

wget http://pecl.php.net/get/imagick-3.3.0.tgz
tar -xvzf imagick-3.3.0.tgz
cd imagick-3.3.0/
phpize
./configure
sudo checkinstall
sudo php5enmod imagick

All that remains is to restart PHP:

service php5-fpm restart

Manually installing the ImageMagick PHP Module for PHP7

Please note: In order to run "phpize" you may need to first install "php7.0-dev" so run "apt-get install php7.0-dev".

First, we need to identify the latest version of the module from the PECL repository that support PHP7, then update the steps below with that version number (at the time of writing that is a beta version, 3.4.0 Release Candidate 3):

wget http://pecl.php.net/get/imagick-3.4.0RC3.tgz
tar -xvzf imagick-3.4.0RC3.tgz
cd imagick-3.4.0RC3/
phpize
./configure
sudo checkinstall

Next, we need to enable the module, unfortunately for PHP7 there doesn't seem to be an equivalent to the "php5enmod" command yet.  So "php7enmod" or "php7.0enmod" did not work, "phpenmod" did appear to run but didn't seem to actually do anything!

So we have to manually enable the module:

cd /etc/php/7.0/mods-available

Create a new file "imagick.ini" with the following contents:

; configuration for php imagick module
; priority=20
extension=imagick.so

Then symlink the INI file we just created to the conf.d folder in the PHP7 install:

ln -s /etc/php/7.0/mods-available/imagick.ini /etc/php/7.0/fpm/conf.d/20-imagick.ini

All that remains is to restart PHP

service php7.0-fpm restart

Tagged with:

You might also like… How to: Upgrade PostgreSQL on Ubuntu