GraphicsMagick and gmagick php module on shared hosting

How to install and configure GraphicsMagick and gmagick php module/extension on shared hosting ? (and build them to be used with ImageMagick/imagick also installed)

This is nearly the same process described for ImageMagick / imagick here: ImageMagick and imagick php module on shared hosting

Prerequisites

 * ssh account activated
 * PHP 5.3 used

Steps

 * Prepare the environment
 * Install GraphicsMagick
 * Build gmagick php extension
 * Configure PHP to use this extension

Prepare the environment
$ mkdir build $ mkdir local
 * Login with ssh to your account, all the operation described below will be done in this ssh connection.
 * Create a "build" directory where all the required tools will be downloaded, configured and then compiled
 * Create a "local" directory where all the required tools will be deployed

Install GraphicsMagick
$ cd build $ wget "ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.17.tar.bz2" $ tar jxvf GraphicsMagick-1.3.17.tar.bz2
 * Download GraphicsMagick

Note: At least with GraphicsMagick 1.3.18, this step is no more required.
 * Fix a little typo before building

In order to have gmagick and imagick extensions active at the same time, a little modification is required.

In GraphicsMagick-/magick/symbol.h, the following line: must be replaced by this one:
 * 1) define UnregisterMACImage GmUnregisterMATImage
 * 1) define UnregisterMACImage GmUnregisterMACImage

In my case the downloaded version was GraphicsMagick-1.3.17, adapt the following command to your downloaded version ... $ cd GraphicsMagick-1.3.17 $ ./configure --prefix=$HOME/local --enable-shared --enable-symbol-prefix $ make $ make install
 * Configure and make GraphicsMagick

If everything ran smoothly, up-to-date GraphicsMagick binaries, libs collection, documentation etc are available in your "local" directory (and sub-directory)

$ export PATH=$HOME/local/bin:$PATH
 * Now you start using this "local" directory ...

Build gmagick PHP module
$ cd $HOME/build

Visit http://pecl.php.net/package/gmagick and choose the version you want to use ... In my case, I took the latest version : 1.1.2RC1 ... Adapt the following commands with the choosen version : $ wget "http://pecl.php.net/get/gmagick-1.1.2RC1.tgz" $ tar zxvf gmagick-1.1.2RC1.tgz $ cd gmagick-1.1.2RC1

Now we need some tricks to make imagick compilation more smooth ... $ phpize $ export PKG_CONFIG_PATH=$HOME/local/lib/pkgconfig $ ./configure --prefix=$HOME/local --with-gmagick=$HOME/local --with-php-config=/usr/local/php53/bin/php-config $ make

Several compilation warnings, don't be afraid .. The important thing is:

Libraries have been installed in: /home/ /build/gmagick-1.1.2RC1/modules

Configure PHP to use this extension
If you don't already have a .php/5.3 directory, create it. Then:

$ cd $HOME/.php/5.3 $ mkdir extensions $ cp $HOME/build/gmagick-1.1.2RC1/modules/gmagick.so extensions $ echo "extension = $HOME/.php/5.3/extensions/gmagick.so" >> phprc