Monday, December 29, 2008
Installing the Perl Image::Magick module on CentOS 5.2As part of migrating the Fourmilab server farm to CentOS 5.2, I am also updating the Movable Type installation used to maintain this chronicle from version 3.34 to the current 4.23 release. Movable Type uses the Image Magick package, through its Perl bindings, to produce thumbnail images for images uploaded for inclusion in pages. While many Linux distributions, including CentOS, provide ready-to-install packages for Image Magick, it's usually up to you to install the Perl module which provides access to the Image Magick library from Perl programs. There are some subtleties in getting this to work, which occasioned some hair pulling on my part. As I have little hair to spare, I thought I'd share my notes for others confronted with the same task, and as a memo to my future self the next time an update comes around. First of all, before undertaking a task, the sage and wily programmer first verifies whether it's necessary at all. Run the Movable Type installation check program, mt-check.cgi in your Movable Type CGI directory, and see whether the Image::Magick module is already installed. If it reports something like, “Your server has Image::Magick installed (version 6.2.8)” you're in business and, as long as image thumbnail generation works, you need do nothing more. If Image::Magick is highlighted as absent, read on. Next, see if the Image Magick binary and library packages are installed on your system. For systems like CentOS which use the RPM package manager, you can do this with the command:
rpm -aq | grep ImageMagickTo install the Perl module, you need three packages:
ImageMagick ImageMagick-devel ImageMagick-perlNote that “ImageMagick-perl” provides the prerequisites for the Perl module, but not the module itself. If one or more packages are missing, install them. On CentOS and like systems, you can do this with, for example:
su yum install ImageMagick-devel(If your system uses a different package manager, you will have to use its equivalent tools, graphical or command line, to check whether the packages are present and install them if not.) After you have installed the three required packages, make a note of the version reported by the “rpm -aq” command. For the current release of CentOS 5.2, the ImageMagick package is reported as “ImageMagick-220.127.116.11-4.el5_1.1” in which the version is 6.2.8. People familiar with installing Perl packages would usually, at this point, go off to CPAN to search for and download the Image::Magick Perl module. But be very careful before you do this, as it may end badly. The Image Magick Perl bindings include C code which is sensitively dependent upon the version of the Image Magick library installed on your machine. In general, you must use a version of the Perl module which was specifically built for use with the corresponding version of Image Magick. The module posted on CPAN is usually one for the most recent general release of Image Magick, but many Linux distributions, especially those focused on stability such as CentOS, follow several versions behind in order to let problems be discovered and corrected before software is deployed in a server environment. For example, at this writing, the current public release of Image Magick is 6.4.8 while CentOS ships with version 6.2.8. If you attempt to build a Perl module intended for a 6.4 release with the libraries from 6.2, you will get hundreds of compilation errors in the C binding code and utterly fail in the installation process. What you need to do instead (unless you're lucky and your Linux distribution does provide the same version of the libraries as the module on CPAN expects) is to go to the Image Magick archives on SourceForge and download the complete source code distribution for the version which corresponds to that installed on your system. Extract the downloaded source code archive into a directory, but do not proceed to build the application and libraries. Instead, simply enter the PerlMagick subdirectory and build and install the Perl module manually with:
cd PerlMagick perl Makefile.PL make su make installAs noted, only the last step must be performed as super-user. (Obviously, only proceed with the installation if the make was successful.) It is not unusual to get some compiler warnings when building this package, but there should be no errors. After installing the Image::Magick module, re-run the Movable Type installation check program (mt-check.cgi) to confirm that it is able to locate it. Then you should try uploading an image to Movable Type with a thumbnail to verify that the process is working properly. If so, you're done.
Posted at December 29, 2008 17:01