Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick installation MediaTemple GridServer

I've activated the ImageMagick extension as per the KnowledgeBase article

Basically, adding this line to php.ini:

open_basedir = /nfs:/tmp:/usr/local:/etc/apache2/gs-bin:/usr/bin/convert

However, this doesn't seem to work.
This script outputs the version number just fine:

$IM_version=shell_exec("/usr/bin/convert -version");
echo $IM_version;

However, when I try to use the Imagick class I get an error.

try
{
        /*** a new imagick object ***/
        $im = new Imagick();

        /*** Create a red rectangle  ***/
        $im->newImage( 200, 100, "red", "png" );

        /*** write image to disk ***/
        $im->writeImage( '/tmp/rectangle.png' );

        echo 'Image Created';
}
catch(Exception $e)
{
        echo $e->getMessage();
}


Error:

Fatal error: Class 'Imagick' not found in /xxxxxxxxxxxxxxx/html/mt.php on line 8

Any ideas what I'm doing wrong or what the next step for troubleshooting is?

I've contacted MediaTemple support and they just said "sorry but because the script outputs the version number it proves it's installed"

like image 527
ahren Avatar asked Aug 29 '13 19:08

ahren


1 Answers

Ok, I got this working but it was a bit tricky. Here goes...

First, you'll want to install ImageMagick from source. This step may be optional if you already have access to 'MagickWand-config', but it wasn't in my path. Here were the steps I followed to install it into an alternate directory on the (gs):

Note: As of this post, the latest release was 6.8.9.3.

$ wget http://www.imagemagick.org/download/ImageMagick-6.8.9-3.tar.gz
$ tar xvfz ImageMagick-6.8.9-3.tar.gz
$ cd ImageMagick-6.8.9-3
$ mkdir /home/#####/etc/imagemagick
$ ./configure --prefix=/home/#####/etc/imagemagick
$ make
$ make install

The Imagick PHP class is a PECL extension so we will install it using the provided KB from Media Temple with one change. Here are the steps:

$ export SITEID=`pwd | awk -F\/ '{ print $3 }'`
$ export PHPPATH=`php-stable -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"`
$ mkdir /home/$SITEID/data/lib
$ mkdir /home/$SITEID/data/lib/php/
$ wget http://pecl.php.net/get/imagick && tar zxvf imagick && cd imagick-* && $PHPPATH/bin/phpize

This is where our script deviates from the instructions. We need to specify the path to our ImageMagick install to use 'MagickWand-config'. If this isn't specified, you'll see the following error:

checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.

If you've used an alternate location for the source install of ImageMagick, replace the path for '--with-imagick' with that path.

$ ./configure --with-php-config=$PHPPATH/bin/php-config --with-imagick=/home/#####/etc/imagemagick

Resuming the normal instructions:

$ make && cp modules/*.so /home/$SITEID/data/lib/php

Update your php.ini file, which should be located at /home/#####/etc/php.ini and add these 2 lines:

extension_dir=/home/#####/data/lib/php/

extension = imagick.so

Once complete, here is the script I ran:

<?php

$IM_version=shell_exec("/usr/bin/convert -version");
echo $IM_version;

if (!extension_loaded('imagick'))
{
    echo "imagick not installed\n";
}
else
{
    echo "imagick installed\n";
}


try
{
        /*** a new imagick object ***/
        $im = new Imagick();

        /*** Create a red rectangle  ***/
        $im->newImage( 200, 100, "red", "png" );

        /*** write image to disk ***/
        $im->writeImage( '/tmp/rectangle.png' );

        echo 'Image Created';
}
catch(Exception $e)
{
        echo $e->getMessage();
}

Output:

Version: ImageMagick 6.6.0-4 2012-05-03 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP 

imagick installed
Image Created
like image 60
Chris Rasco Avatar answered Nov 09 '22 09:11

Chris Rasco