Imagick on CentOS6 with PHP 5.4 and ImageMagick latest

Installing imagick php module on a CentOS 6 system a pain in the ass when using it with a rather new ImageMagick version and PHP 5.4+

By default CentOS uses a rather old version of ImageMagick in it’s distribution. I liked to have a newer version for some reasons while developing an application.

So here is a working howto:
ImageMagick 6.8.5.9
PHP 5.4.17
CentOS 6.4 on an x86_64

First remove the old versions:

yum remove ImageMagick ImageMagick-devel

then install the newer version using REMI repo:

yum –enablerepo=remi install ImageMagick-last ImageMagick-last-devel

This brings you version 6.8.5.9-1

Now ImageMagick being installed, it is time for compiling imagick.

It is  known that with PHP 5.4 you HAVE  to use Imagick-3.1.0RC2
Older versions won’t work unfortunately.
I am not a fan of using Release Candidates on my servers. But in this case I have to live with that.
As a webhost i have to say: this is the reason why webhosters so often are behind with their PHP versions.

cd /tmp  (or choose whatever directory you want for temp downloads)

wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz

tar zxf imagick-3.1.0RC2.tgz

cd imagick-3.1.0RC2

phpize

Now here’s another catch when using Release  Candidates:
configure cannot find the path to ImageMagick-6
So you have to create a symbolic link to it:

ln -s /usr/local/include/ImageMagick-6 /usr/local/include/ImageMagick

./configure

make

make test

make install

Now you have to tell PHP to use the imagick module by adding “extension=imagick.so” to php.ini

I personally prefer to create an include file in  /etc/php.d

nano -w /etc/php.d/imagick.ini

and put following line in it:  extension=imagick.so

then restart apache: service httpd restart

now check if it is there with a php file in your webspace asking for phpinfo()
You should see something like:

Imagick

imagick module enabled
imagick module version 3.1.0RC2
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version ImageMagick 6.8.5-9 2013-06-02 Q16 http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2013 ImageMagick Studio LLC
ImageMagick release date 2013-06-02

…and some more info.

Or check  your php version via command line:

php -v

There should be no warnings or errors.