PHP5.4, Imagemagick & Pecl Installation [Ubuntu]

After upgrading to PHP 5.4.x, by using source compilation method, I realised our PHP was missing imagemagick extension.

ImageMagick is replacement for php’s default GD library which WordPress uses for creating thumbnails on the fly. Using ImageMagick WordPress plugin, you can tell WordPress to use ImageMagick rather than PHP’s default GD library. But for this to work your PHP must have ImageMagick extension enabled.

Installing & Enabling ImageMagick using Pecl

You need install ImageMagick package first

apt-get install imagemagick libmagick9-dev php5-imagick

If you get error:

Package ‘libmagick9-dev’ has no installation candidate


apt-get install imagemagick libmagickwand-dev php5-imagick

Installation is just 1-command job (usually)

pecl install imagick

But at the time of writing this post, when running above command against php5.4.x, installation will fail with following error:

/tmp/pear/temp/imagick/imagick_class.c:9534:2: error: 'struct _php_core_globals' has no member named 'safe_mode'

By default, pecl attempt to install stable build of imagick which as of today is not ready for PHP5.4. But they already have RC build here –

To force, pecl to install RC build, run following command:

pear config-set preferred_state beta

Now you can attempt installation again:

pecl install imagick

This time it should work! You will see output like below:

 Build process completed successfully
 Installing '/opt/php5/lib/php/extensions/no-debug-non-zts-20100525/'
 Installing '/opt/php5/include/php/ext/imagick/php_imagick.h'
 Installing '/opt/php5/include/php/ext/imagick/php_imagick_shared.h'
 Installing '/opt/php5/include/php/ext/imagick/php_imagick_defs.h'
 install ok: channel://
 configuration option "php_ini" is not set to php.ini location
 You should add "" to php.ini

As suggested by last line, do not forget to add following line in php.ini

You may need to restart PHP-FPM or your web server.

service php5-fpm restart


Georgi October 9, 2012

Great! This post helped me install imagemagick! Thanks!

Aleka February 13, 2013

Thanks for your post. I had a good time trying to install it.

Mike March 20, 2013

Thanks so much! you have NO IDEA how hard i had to look for this solution.

This worked perfectly for my VPS Cpanel 11.36 CenOS6 PHP 5.4

Mario Martinez July 24, 2013

Many Thanks!!!, the error “struct _php_core_globals”, makes me going mad. On CENTOS 5 this method works perfectly, (just obviously adapting it with yum installer)

Eoin August 10, 2013

Thanks, your idea worked for me but the method did not.
pecl refused to download the beta package using your method.

pecl install packagename-beta
did the trick though.


rijo August 16, 2013

This method works with no sweat.
It even added the extension by itself in php.ini.

Build process completed successfully
Installing ‘/usr/local/include/php/ext/imagick/php_imagick_defs.h’
Installing ‘/usr/local/include/php/ext/imagick/php_imagick_shared.h’
Installing ‘/usr/local/include/php/ext/imagick/php_imagick.h’
Installing ‘/usr/local/lib/php/extensions/no-debug-non-zts-20100525/’
install ok: channel://
Extension imagick enabled in php.ini

Resulting Output
#cat /usr/local/lib/php.ini | grep imagick