The Storyteller

Installing Imagick extension for PHP in Ubuntu 7.10

February 6, 2008 · 13 Comments

I already have ImageMagick installed in my machine and I tried to install the Imagick extension for PHP but I was stuck with strange errors. I have spent couple of hours today to figure out what I did wrong and Why I cant build that extension. Finally I’ve figured out that I must install ImageMagick from source first to build that extension. Heres how to

1. You have to install ImageMagick from source and Its a Must. Otherwise the extension for PHP wont compile. It will show you a strange error like magic_wand.h not found.

wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar zxf ImageMagick.tar.gz
cd ImageMagick-6.3.8
./configure
sudo make
sudo make install

2. Now download the Imagick extension source from pecl.php.net – I tried imagick-2.1.0RC3

wget http://pecl.php.net/get/imagick-2.1.0RC3.tgz
tar zxf imagick-2.1.0RC3.tgz
cd imagick-2.1.0RC3
phpize && ./configure
sudo make
sudo make install

This will make compile imagick source and build imagick.so – In my machine, I found imagick.so in the following directory

/usr/lib/php5/20060613+lfs

3. Now add “extension=imagick.so” in your php.ini (You may need to write the full path of imagick.so based on your configuration)

4. Restart your web server and thats it

Look at the php ini – you will see something like below (Click to enlarge)

Imagick

Categories: PHP

13 responses so far ↓

  • elzapp // February 7, 2008 at 1:32 am | Reply

    THANKS!

    I would have found a solution to this myself eventually, but now I don’t have to. Any idea why the Ubuntu packages are broken?

  • Sascha // February 7, 2008 at 1:47 am | Reply

    Probably version conflicts.. ubuntu comes with imagemagic 6.2.x in edgy and hardy (for now). You have 6.3.x.

    But installing the official php5-package for imagick extension worked just fine for me, it is however an older version: (This is hardy, edgy is similar, just an older verson.. 2.0.0-alpha)

    ~$ sudo apt-get install php5-imagick
    Paketlisten werden gelesen… Fertig
    Abhängigkeitsbaum wird aufgebaut
    Reading state information… Fertig
    The following packages were automatically installed and are no longer required:
    libfftw3-3
    Verwenden Sie »apt-get autoremove«, um sie zu entfernen.
    Die folgenden NEUEN Pakete werden installiert:
    php5-imagick
    0 aktualisiert, 1 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.
    Es müssen 84.0kB Archive geholt werden.
    After this operation, 397kB of additional disk space will be used.
    Hole:1 http://archive.ubuntu.com hardy/universe php5-imagick 2.0.1-1 [84.0kB]
    Es wurden 84.0kB in 0s geholt (252kB/s)
    Wähle vormals abgewähltes Paket php5-imagick.
    (Lese Datenbank … 155696 Dateien und Verzeichnisse sind derzeit installiert.)
    Entpacke php5-imagick (aus …/php5-imagick_2.0.1-1_amd64.deb) …
    Richte php5-imagick ein (2.0.1-1) …

    Creating config file /etc/php5/conf.d/imagick.ini with new version

    $ php -i | grep imagick
    additional .ini files parsed => /etc/php5/cli/conf.d/imagick.ini,
    imagick
    imagick module => enabled
    imagick module version => 2.0.1
    imagick classes => Imagick, ImagickDraw, ImagickPixel

  • James // February 7, 2008 at 4:35 am | Reply

    The better way to install the pecl package is:

    $ sudo pecl upgrade imagick
    or
    $ sudo pecl install imagick

    Just like using PEAR, you can choose stable, beta or alpha packages.

    I had a similar problem with Ubuntu’s php5-imagick package, uninstalled and grabbed the PECL package, which works well and gives me access to all the latest methods.

    I found some problems with restarting Apache after upgrading Imagick:

    $ sudo apache2ctl configtest
    Syntax OK
    $ sudo apache2ctl restart
    $ ps -ef | grep apache
    james 12282 9338 0 09:31 pts/4 00:00:00 grep apache
    $ sudo apache2ctl start
    $ ps -ef | grep apache
    root 12328 1 6 09:31 ? 00:00:00 /usr/sbin/apache2 -k start

    Here is what apache error log says for the above, snipped for brevity:
    [Thu Feb 07 09:31:12 2008] [notice] SIGHUP received. Attempting to restart
    [Thu Feb 07 09:31:12 2008] [notice] seg fault or similar nasty error detected in the parent process
    [Thu Feb 07 09:31:23 2008] [warn] pid file /var/run/apache2.pid overwritten — Unclean shutdown of previous Apache run?
    [Thu Feb 07 09:31:23 2008] [notice] Apache/2.2.4 (Ubuntu) configured — resuming normal operations

  • Mikko Koppanen // February 7, 2008 at 5:36 am | Reply

    You need to install the package libmagick9-dev. This package contains the necessary headers to compile Imagick.

  • hasin // February 7, 2008 at 8:51 am | Reply

    @Mikko

    I tried installing graphicsmagick-libmagick-dev-compat but libmagick9-dev, because afaik Wand_config was available to both these packages. It installed suucessfully but when I tried to compile Imagick extension, it ends up with the same error magic_wand.h not found.

    Thanks for the info.

  • hasin // February 7, 2008 at 8:56 am | Reply

    @James

    Until I had built ImageMagick from source, “pecl install imagick” ended up with same error.

  • Mikko Koppanen // February 9, 2008 at 10:59 pm | Reply

    GraphicsMagick backend is no longer supported. libmagick9-dev also provides the magick-wand.h header that is required to compile Imagick.

  • stylephreak // April 11, 2008 at 11:45 am | Reply

    Fantastic post! Thanks very much.

  • Suresh Kumar // June 10, 2008 at 9:10 pm | Reply

    Really this POST helped me a lot. I am using Redhat version , ok i will try to use this tips to implement in my server and let see it works or not.

  • Mauro Pirrone // July 18, 2008 at 7:14 pm | Reply

    Thanks very much :)

  • Weva Consulting // November 25, 2008 at 9:15 pm | Reply

    Thanks you, your guide help me upgraded ImageMagick and imagick pretty straightforward.

  • Rob // January 5, 2009 at 9:06 pm | Reply

    Hey thanks man!
    After struggeling with the install for hours I finally made it!
    HELLO WORLD :)

  • alex // August 31, 2009 at 1:12 am | Reply

    PHP Warning: PHP Startup: Unable to load dynamic library ‘…/imagick.so’ – …/imagick.so: undefined symbol: XStringListToTextProperty in Unknown on line 0 la soulucion en suse fue la instalacion de rc2e
    luego el proceso nomarl de instalcion
    pecl install imagick

    cuando pida la ruta coloca la ruta de extencion de php
    /usr/php5/extencion/

    ….
    en la carpeta de imagick ejecuta lo siguiente
    ….
    #phpize
    #./configure
    ….
    service apache2 stop
    service apache2 start

    en el php.ini
    extencion=imagick.so

Leave a Comment