This was tested on CentOS 5.6 on a fresh MediaTemple (dv) setup. I figure it should be the same for any CentOS install. This set of instructions is a result of hours spent on installation troubleshooting; google searches; and trial and errors. Hopefully this can help other people.
Install dependencies
These are needed to enable GraphicsMagick add-ons. In here, I only included what I think are commonly required. But feel free to include other libraries that you need.
$ yum install -y gcc libpng libjpeg libpng-devel libjpeg-devel ghostscript
$ yum install -y libtiff libtiff-devel freetype freetype-devel
Download and install GraphicsMagick
We will need to download and compile GraphicsMagick ourselves. It looks like it is not available in yum
yet. MediaTemple users are advised to
use chroot
to prevent noexec
and /tmp
related errors.
Execute these on the console:
# work on a temporary dir of your preference
cd /root/tmp
# download source tarball. See here for other versions: ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/
wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.9.tar.gz
# extract and open the extracted folder
tar -xvf GraphicsMagick-1.3.9.tar.gz
cd GraphicsMagick-1.3.9
./configure --enable-shared
Using --enable-shared
above has helped prevent errors like this when installing gmagick through pecl:
Build Error: /usr/bin/ld: /usr/local/lib/libGraphicsMagickWand.a(drawing_wand.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
After ./configure
is done, make sure that the Configured value of the add-ons you need are set to Yes
. Also make sure that
enable-shared
is set to Yes
. You can see this at the end part of configure
’s output. It should look like this:
Option Configure option Configured value ------------------------------------------------------------------ Shared libraries --enable-shared=yes yes Static libraries --enable-static=yes yes GNU ld --with-gnu-ld=yes yes Quantum depth --with-quantum-depth=8 8
Delegate Configuration: BZLIB --with-bzlib=yes no DPS --with-dps=yes no FlashPIX --with-fpx=no no FreeType 2.0 --with-ttf=yes yes Ghostscript None gs (8.70) Ghostscript fonts --with-gs-font-dir=default /usr/share/fonts/default/Type1/ Ghostscript lib --with-gslib=no no JBIG --with-jbig=yes no JPEG v1 --with-jpeg=yes yes JPEG-2000 --with-jp2=yes no LCMS --with-lcms=yes no Magick++ --with-magick-plus-plus=yes yes PERL --with-perl=no no PNG --with-png=yes yes TIFF --with-tiff=yes yes TRIO --with-trio=yes no Windows fonts --with-windows-font-dir= none WMF --with-wmf=yes no X11 --with-x= no XML --with-xml=yes no ZLIB --with-zlib=yes yes
Next, compile and install:
make
make install
You can then test if GraphicsMagick has been successfully installed by executing commands like:
gm version
Install Gmagick PHP extension
We’ll install gmagick using PECL. MediaTemple users are still advised to use chroot
.
pecl install gmagick
If you get an error about gmagick not having a stable version, you can specify the version instead:
pecl install gmagick-1.0.8b2
Next, add extension=gmagick.so
to php.ini
and restart Apache if necessary. This is outside the scope of this article though. Please Google it if you don’t know how.
And we’re done!
P.S. If you’re having trouble, it might help to look/search for solutions using “ImageMagick” instead. There are fewer resources for GraphicsMagick compared to ImageMagick. I found some articles for ImageMagick that can be used for GraphicsMagick too.