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
yum install ImageMagick-devel
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

24 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

    • I have got: Fatal error: Uncaught exception ImagickException’ with msagese PostscriptDelegateFailed No such file or directory’ in The thing is that from the command line it’s working (meaning running PATH/convert -density AxB -quality 100 PATH/from.pdf PATH/to.jpg ) but NOT with Imagick PHP extension.NOTE: This is happening ONLY from some PDF’s, meaning for others (with the same number of pages, if it matters ) it’s working just fine.I only saw a really strange thing, when converting from CMD the PDF’s that are not working from within PHP with images->readImage($pdfPath) there is a STRANGE behavior meaning there is a 80% conversion time where the processor it’s not heavily loaded.Of course the same not-working PDF can be converted ok from PHP with exec (it takes the same amount of time as from CMD, but much more to complete as the one working with Imagick).It’s not a path issue as I’m always using full paths. Just replacing that non-working (I mean within PHP Imagick extension) PDF with one who always was ok and I get my pictures .All this on a Windows platform as a Linux one too (really don’t know what version has the Linux one ). Seems to be something about that PDF’s (because I have more); don’t know what, could be the fonts used?Help!

  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

  16. Interesting guide! Those steps did not work for me at all, and when I run the test code with “grep imagick,” I get:

    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/imagick.so’ – /usr/lib64/php/modules/imagick.so: undefined symbol: MagickGetImageBluePrimary in Unknown on line 0
    PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib64/php/modules/imagick.so’ – /usr/lib64/php/modules/imagick.so: undefined symbol: MagickGetImageBluePrimary in Unknown on line 0

    The real problem is that there is no imagick.so file within the php.d folder. (Problematic.)

    However, I did get it working 100%!!! (After almost a week of working on this.) My solution, from scratch:

    1. Install CentOS 6.4.
    2. Install PHP, PHP-Common, PHP-extensions, etc., from standard Application Package Manager.
    3. From admin mode (“su” command), command: yum install ImageMagick ImageMagick-devel
    4. Command: pecl install imagick
    5. Modify php.ini and include the line “extension=imagick.so”.
    6. Command: service httpd restart

  17. malcolmsager

    Hi, everything is going fine here and ofcourse every one
    is sharing data, that’s truly fine, keep up writing.

  18. I will just leave a not for others that might be as stupid as me. If you are running a 64 bit server, a x86_64 architecture don’t run these commands as is because .i386 isn’t the same. So just do:

    yum install ImageMagick-devel
    pecl install imagick

    The system will identify the x86_64 and install it. Maybe the author should update this post and remove .i386 from the command.

    Thanks!

Leave a Reply