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

6 Replies to “PHP5.4, Imagemagick & Pecl Installation [Ubuntu]”

  1. 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

  2. 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)

  3. 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.


  4. 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

Comments are closed.