Install imagemagick with PHP imagick extension on CentOS

To install imagemagick with PHP imagick extension on Linux CentOS you must follow these steps:

yum install ImageMagick.i386
yum install ImageMagick-devel.i386
pecl install imagick

If you have an error like this:
root@myhost [~]# pecl install imagick
downloading imagick-3.0.1.tgz ...
Starting to download imagick-3.0.1.tgz (93,920 bytes)
.....................done: 93,920 bytes
13 source files, building
running: phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
Please provide the prefix of Imagemagick installation [autodetect] :
building in /var/tmp/pear-build-root/imagick-3.0.1
running: /root/tmp/pear/imagick/configure --with-imagick
checking for egrep... grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
ERROR: `/root/tmp/pear/imagick/configure --with-imagick' failed

Look at your /tmp folder… pretty surely it is mounted with noexec flag. Remount it without noexec and retry:
mount -o remount,rw /tmp

At the end of the installation, create an inclusion file for imagick.so module and restart apache:

echo "extension=imagick.so" > /etc/php.d/imagick.ini
/etc/init.d/httpd restart

Test the correct loading of the imagick module with:
php -m | grep imagick

19 Comments

  1. Thanks for some quality points there. I am kind of new to online , so I printed this off to put in my file, any better way to go about keeping track of it then printing?

  2. Do you people have a facebook fan page? I looked for one on twitter but could not discover one, I would really like to become a fan!

  3. Thank for this! I was looking this long time!

  4. It worked! Thank you

  5. Job

    Using this method.. no need to edit the php.ini?

    • You don’t need to edit php.ini directly.
      The module inclusion is done in /etc/php.d/imagick.ini

  6. Just went through this. Just a note for those on CentOS 5.6 (probably more), you’ll want to run ‘yum install ImageMagick-devel’ (for some reason yum install ImageMagick-devel.i386 didn’t work) to avoid the following error: ‘configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.’

    Also, incase you don’t have it, if pecl doesn’t work, run ‘yum install php-pear’. I know, noobish, but pertinent.

  7. @Curtis Just install ImageMagick from source and re-try pecl install.

    • I have a problem gaeiretnng PDF files resulting in a completely blank page when using setResolution, if I switch to writing a JPG file everything works fine.If I skip setResolution my target PDF will be generated but ofc with very poor quality so I need the setResolution functionality.I have done some testing with various different sources/templates both JPG, PNG and PDF files, some will result in blank PDF files others will work fine, I can’t find a common attribute that should provoke this, neither filetype, colorspace, resolution or DPI have anything in common with the tests I’ve done code looks something like this: $file = files/card_templates/random.pdf[1] ; $template = new Imagick(); $template->setResolution(300, 300); //Skip this to generate PDF, results in poor quality though $template->readImage($file); $template->setImageFormat( pdf ); //Doing some manipulation here but it doesn’t have any effect on the problem. $template->setImageCompressionQuality(100); $path = img/tmp/final.png’; $template->writeImages($path, true); //Works fine, high quality png $path = img/tmp/final.pdf’; $template->writeImages($path, true); //Results in blank PDFAny help would be appreciated, thanks

  8. I needed this to run my ne webstie ;) Thanks in advance!

  9. This web site is truly a walk-through for all of the information you wanted about this and didnt know who to ask and my seotons. Glimpse here, and youll definitely discover it.

  10. Hello,
    I am running the command but as soon as I run it, it is giving me a weird error:

    pecl install imagick
    downloading imagick-3.0.1.tgz …
    Starting to download imagick-3.0.1.tgz (93,920 bytes)
    ………………done: 93,920 bytes
    13 source files, building
    running: phpize
    grep: /usr/include/php/main/php.h: No such file or directory
    grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
    grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
    Configuring for:
    PHP Api Version:
    Zend Module Api No:
    Zend Extension Api No:
    cp: cannot stat `mkdep.awk’: No such file or directory
    cp: cannot stat `scan_makefile_in.awk’: No such file or directory
    cp: cannot stat `shtool’: No such file or directory
    cp: cannot stat `libtool.m4′: No such file or directory
    cp: cannot stat `acinclude.m4′: No such file or directory
    cp: cannot stat `Makefile.global’: No such file or directory
    cp: cannot stat `config.sub’: No such file or directory
    cp: cannot stat `config.guess’: No such file or directory
    cp: cannot stat `ltmain.sh’: No such file or directory
    cp: cannot stat `run-tests*.php’: No such file or directory
    cat: acinclude.m4: No such file or directory
    cat: ./build/libtool.m4: No such file or directory
    /usr/bin/phpize: line 154: /usr/lib64/php/build/phpize.m4: No such file or directory
    chmod: cannot access `/var/tmp/imagick/build/shtool’: No such file or directory
    shtool at ‘/var/tmp/imagick/build/shtool’ does not exist or is not executable.
    Make sure that the file exists and is executable and then rerun this script.

    ERROR: `phpize’ failed.

    Can anyone help me with this issue?

    Thanks for looking.

    Parikshit

  11. Parikshit, you need to install also autoconf and m4 to fix your issue.

  12. gps

    Hello,
    I’m running to install imagik with pecl with command: pecl install imagik
    Then error occurs as you describe:
    ERROR: `/root/tmp/pear/imagick/configure –with-imagick’ failed
    I’m tried to:
    mount -o remount,rw /tmp
    But system return:
    mount: can’t find /tmp in /etc/fstab or /etc/mtab
    What can I do now? Please help me.
    Sorry about my English :)

    • Usually that error is reported when the /tmp is mounted with -noexec flag.
      Can you post the output of the mount command?

  13. Why not just

    yum install php-pecl-imagick

    Seems like it saves a lot of headaches.

    • Hi Mikko,Web site is great. i was using imagemagick cmomand line tool, now i want to use imagick api. i am currently working an online shop (about printing, similar to shutterfly.com). My question is;could i use imagick without any restriction, like imagemagick? Performance is very important. Many high resolution (5000px etc) images are using to create a template, often used crop, resize (at reading image.tif[300x500], composite vs at single line cmomand like convert background[780x560] ( image[200x305.2] ) -geometry +10+10 -crop 5 5+10+10 -composite( image[200x157.92] ) -geometry +237.12+358.96 -composite-draw rectangle 10,10 10,10 .. .. . . longerthank you. realy great source.

  14. Encore merci. J ai vraiment apprecié de lire cette article

  15. Simple and clear