Friday, October 23, 2009

ImageMagick, CentOS, and PHP

Ever wonder how to get ImageMagick to work well in a PHP environment on CentOS?

I have done it a few times, and here's a simple recipe to follow. I use this recipe when I have yum managing the basic libraries, but not managing the libraries in active use on the site (like php, apache, perl, imagemagick and a few others).
% sudo yum install libX11-devel
% sudo yum install libjpeg libjpeg-devel
% sudo yum install libpng libpng-devel
% sudo yum install libtiff libtiff-devel
% # download ImageMagick from ftp://ftp.fifi.org/pub/ImageMagick/
% ./configure --with-perl=/usr/local/bin/perl
% make
% sudo make install
(make sure that /usr/local/lib is in the /etc/ld.so.conf.d/*.conf files)
% sudo /sbin/ldconfig

Now image-magick is installed.

To Use in PHP
% sudo /usr/local/bin/pecl install imagick
% sudo vi /usr/local/lib/php.ini
% sudo /etc/init.d/httpd stop
And that's it. Hope this helps.