install imagick for php

I’ll describe the installation process for Centos as this is my server’s operating system, the installation is very similar for any linux flavour.

In order to have imagick class available inside php firstly we need to install ImageMagick-devel:
1. yum install ImageMagick-devel

then, download & extract the imagick pecl package:
2.a. cd ~
2.b. wget http://pecl.php.net/get/imagick-3.0.1.tgz
2.c. tar -xvf imagick-3.0.1.tgz
2.d cd imagick-3.0.1.tgz

here is a little storry, we need to use phpize to prepare the imagick php extension for compiling.
On my server I have multiple php installations and if I use phpize directly it will compile the extension for a wrong version of php. Even if I try using phpize with an absolute path the end result will still be wrong and I’ll get the following errors inside my apache error log:
“PHP Warning: PHP Startup: imagick: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match”

3. so keeping the story short this is what I did:

export PHP_PREFIX="/usr/local/php-5.3.2"
$PHP_PREFIX/bin/phpize
./configure --with-php-config=$PHP_PREFIX/bin/php-config
make
make install

4. now check where the imagick.so file was copied to and include it in your php.ini:
extension=/usr/…/extensions/no-debug-non-zts-20090626/imagick.so