ImageMagick Install

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I have searched a lot, and also been getting help in these forums, and here I have a complete guide that I can guarantee that will work. However, this is only tested on servers running CentOS 6.x with PHP as suPHP/CGi, however it should be similar on other systems.

Some notes is that ImageMagick and ImageMagick-devel need to be the same versions. Other note is that ImageMagick-devel should NOT be installed using yum, instead install it using rpm without installing any dependency, afterwords we will remove ImageMagick-devel wich is only needed during install.

So here we go, installing ImageMagick and Imagick from source on CentOS 6.3x:

1: Install ImageMagick and ImageMagick-devel using yum because we need all the dependency installed:
Code:
yum install ImageMagick
yum install ImageMagick-devel
2: Remove ImageMagick and ImageMagick-devel using yum:
Code:
yum remove ImageMagick
yum remove ImageMagick-devel
3: Download tar.gz from http://www.imagemagick.org/script/download.php - for example we can choose from United States, like I will do in this example:

Code:
cd /root
wget http://imagemagick.mirrorcatalogs.com/ImageMagick-6.7.9-2.tar.gz
tar zxf ImageMagick-6.7.9-2.tar.gz
cd ImageMagick-6.7.9-2
./configure --with-perl=/usr/bin/perl
make
make install
4: No wee need to install ImageMagick-devel without yum (because we do not want the dependency to be installed). Find the newest version from (this is for CentOS 64bit, also version must be same as ImageMagick version you install previously) http://www.imagemagick.org/download/linux/CentOS/x86_64/ and install it like this:
Code:
cd /root
rpm -i --nodeps http://www.imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-devel-6.7.9-2.x86_64.rpm
5: We are now ready to install Imagick php module. Do it like this:

Code:
find / -name phpize
Look at the result, and use the path in the following export path (modify according to your own path in above code). Here is the command that is correct for my path:

Code:
export PATH=$PATH:/usr/local/php5/bin
Then continue to install Imagick php module (Edit: If you are running php 5.4.x, then you need to install imagick 3.1.0RC2, 3.0.1 will give errors, find it here: http://pecl.php.net/package/imagick ):
Code:
cd /root
wget http://pecl.php.net/get/imagick-3.0.1.tgz
tar zxf imagick-3.0.1.tgz
cd imagick-3.0.1
phpize
./configure
make
make install
6: Next we edit /usr/local/etc/php5/cgi/php.ini (adjust according to your own php.ini path) and add extension. Add this to bottom of your php.ini file:

Code:
extension=imagick.so
Then restart apache:
Code:
service httpd restart
7: Now we should remove ImageMagick-devel wich is no longer needed:
Code:
yum remove ImageMagick-devel
And then we can delete all the not needed files in /root, you can delete these:
Code:
ImageMagick-6.7.9-2
imagick-3.0.1
ImageMagick-6.7.9-2.tar.gz
imagick-3.0.1.tgz
8: Finally if you use suPHP, we need to edit suphp.conf files so that commands like "convert" will work in php without the need to use full path in the commands. Every time you recompile php, you must add back the change in suphp.conf file. Do it like this:

Edit this file: /usr/local/suphp/etc/suphp.conf - find line number 32 wich looks like this:
Code:
env_path="/bin:/usr/bin"
Replace that line with this:
Code:
env_path="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
Then restart apache:
Code:
service httpd restart
Now you can do some tests. First chech a php.info file to see everything is there. Then you can upload a php file to your website with this content:
Code:
<?php
echo "<pre>";
system("which convert"); 
echo "</pre>";
?>
If it works, it will print out the convert path in the page when you view it in a browser. Also, here is some other commands to test in command line that everything looks good and is working:

This will create a logo.gif file in root/logo.gif:
Code:
cd /root
/usr/local/bin/convert logo: logo.gif
Some more commands to test in command line:

Code:
php -m | grep imagick
identify -version
which convert
/usr/local/bin/identify -list format
/usr/local/bin/identify -list configure
I spent a lot of time before I had every problem fixed, and this guide should be perfect for you if you run same system as I do, and want the source install of ImageMagick and Imagic. Follow same steps when upgrading, only you can skip doing step 1 and step 2. Enjoy! :)

Edit: If you are upgrading image magick from previous version, remember to run ldconfig /usr/local/lib or just ldconfig at root level of server - thanks to Trans-IX B.V
Edit: I edited step 5 with this information: If you are running php 5.4.x, then you need to install imagick 3.1.0RC2, 3.0.1 will give errors, find it here: http://pecl.php.net/package/imagick
Edit: I have removed --with-modules from configure command in step 3 to solve this problem: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22223
Edit: As of ImageMagick version 6.8.3-0 it is now needed to have the perl module parent installed, you can install parent using cpan:
Code:
cpan
install parent
Edit: If you in "Step 5" when doing ./configure get this error: checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h - then it is because of change in newer versions folder name and because imagick has hardcoded the folder name, you can fix it by doing as described in post #13 here http://forum.directadmin.com/showthread.php?t=45957&p=238929#post238929
 
Last edited:

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I have upgraded ImageMagick several times after this guide, and never had any problems, until today. I am trying to upgrade from ImageMagick 6.7.9-10 to ImageMagick 6.8.0-4, but get this error when doing "make" command:

Code:
 CCLD     magick/libMagickCore.la
/usr/bin/ld: /usr/local/lib/libltdl.a(ltdl.o): relocation R_X86_64_32S against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libltdl.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [magick/libMagickCore.la] Error 1
make[1]: Leaving directory `/root/ImageMagick-6.8.0-4'
make: *** [all] Error 2
 
Last edited:

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
As mentioned here http://www.imagemagick.org/discourse...hp?f=3&t=22223 the solution was to remove --with-modules from configure command in step 3. Here is quotes from the above link:

Remove --with-modules from your configure script command line or rebuild libltdl with the -fPIC option.
ImageMagick no longer include the libltdl source distribution. Instead it looks for the distribution on the host its built on.
So the change that ImageMagick no longer include the libltdl source distribution was done from ImageMagick version 6.8.0-x, versions older then that include libltdl.
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I have updated the guide by adding a new "Edit" at the bottom. As of ImageMagick version 6.8.3-0 it is now needed to have the perl module parent installed.
 

chaser010

Verified User
Joined
Sep 12, 2006
Messages
13
I can't get imagick to work with PHP5.3:

[root@server imagick-3.0.1]# /usr/local/php5/bin/php-cgi -v
PHP Warning: PHP Startup: imagick: Unable to initialize module
Module compiled with module API=20060613
PHP compiled with module API=20090626
These options need to match
in Unknown on line 0
PHP 5.3.23 (cgi-fcgi) (built: Apr 4 2013 22:41:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
Before compiling imagick and using phpize it shows:
[root@server imagick-3.0.1]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
I only have the following:
/usr/local/lib/php/extensions/no-debug-non-zts-20060613/
cannot find
no-debug-non-zts-20090626/
Please help.
 

uberook

New member
Joined
Apr 14, 2013
Messages
1
Try the following if you're on Centos or alike:

yum install php-devel ImageMagick ImageMagick-devel
pecl install Imagick


don't forget to add this to php.ini
extension=imagick.so

and then

service httpd restart
 

chaser010

Verified User
Joined
Sep 12, 2006
Messages
13
Thanks,

imagick was compiled for the wrong PHP version, so I fixed it like this:
./configure --with-php-config=/usr/local/php5/bin/php-config
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I have posted a new edit at the bottom of the guide, it is needed for newer versions of ImageMagick and Imagick:

If you in "Step 5" when doing ./configure get this error: checking for MagickWand.h header file... configure: error: Cannot locate header file MagickWand.h - then it is because of change in newer versions folder name and because imagick has hardcoded the folder name, you can fix it by doing as described in post #13 here http://forum.directadmin.com/showthread.php?t=45957&p=238929#post238929
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,855
Location
GMT +7.00
It seems that on 64 bit CentOS 6.x you still need some 32 bit versions of some libraries. And you can not install ImageMagick ImageMagick-devel both 32 bit and 64 bit. So you first install 32 bit versions, then remove them without deps, and the only install 64 bit versions.

Another issue might come, if you remove ImageMagick-devel after imagick is built. So you might need to keep it. Though did not go into deep details on why the issue rises.
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
You only need ImageMagick-devel when you are installing imagick php exstension, after you have installed imagick, then you can remove ImageMagick-devel (but install it again the next time you are upgrading).

So what I do, is install the correct version from http://www.imagemagick.org/download/linux/CentOS/x86_64/ using this command:

Code:
rpm -i --nodeps http://www.imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-devel-6.8.5-7.x86_64.rpm
Please note you should change version number to be the same as the version of ImageMagick that you are installing.

Then when you are finish installing everything, remove it with yum:

Code:
yum remove ImageMagick-devel
You should not install ImageMagick-devel using yum, it will then give you dependencies with old versions that you do not want when installing ImageMagick and Imagick from source.

About the 32 and 64 bit, I have never needed to do that. I am running CentOS 6.4 64bit, and always only install 64bit versions when installing ImageMagick and Imagick. Just follow everything and the extra notes in this guide, and it should work.

Edit: There is no good reason to keep ImageMagick-devel after you have installed everything. Becauase as said, ImageMagick-devel, should be same versions that ImageMagick you are installing, so you would need to install the new version of ImageMagick-devel every time you upgrade. So my advice is just remove it.
 
Last edited:

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,855
Location
GMT +7.00
I've just followed the guide of yours and ran into an issue:

imagick was compiled good, but imagick.so was not load because of missing libs:

Code:
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libfftw3.so.3: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libfftw3.so.3: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libfftw3.so.3: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libMagickWand-6.Q16.so.1: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libfftw3.so.3: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libMagickWand.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/imagick.so' - libMagickWand.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
To solve the issue with libfftw3.so.3 I had to install 32 bit versions of all dependencies, not too sure why...
If I remove ImageMagick-devel I get this:

Code:
ls: cannot access /usr/lib/libMagickWand.so: No such file or directory
ls: cannot access /usr/lib/libMagickWand.so.2: No such file or directory
ls: cannot access /usr/lib/libMagickWand.so.2.0.0: No such file or directory
ls: cannot access /usr/lib64/libMagickWand.so.2: No such file or directory
ls: cannot access /usr/lib64/libMagickWand.so.2.0.0: No such file or directory
and an issue with loading libMagickWand.so.2.

What do I miss?
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I have never seen any of those warnings. So I don't know. You did install the newest version of imagick 3.1.0RC2? Was ImageMagick previous installed in yum? If so, I would remove it in yum, and then manually find and remove anything left from ImageMagick and Imagick, and start all over. I assume you are installing the newest version of ImageMagick 6.8.5-8? http://www.imagemagick.org/script/changelog.php

My setup is on CentOS 6.4 64bit, running PHP 5.4.15 as mod_php using mod_ruid2. When I first wrote this guide, I was running suPHP. But it should not matter. It is the same, expect the last bit in number 8.

Edit: Please give me ten minutes, I will post all commands I used when last upgrading/installing. I will post it in a reply here.
 
Last edited:

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,855
Location
GMT +7.00
Hm... re-built image once again... no issue with removed ImageMagick-devel. Well, I guess the issue was caused probably by a difference between ImageMagick and ImageMagick-devel versions. Not sure, now.
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I don't know either, but good you got it working. But I do know that they are saying it is important to have the same version of ImageMagick and ImageMagick-devel. I can also mention that one time every month, I upgrade ImageMagick and reinstall Imagick on all 4 servers I have, and it works good doing my own guide. Here is my guide from the last time I upgraded/installed ImageMagick and Imagick:

# For first time install, do this first:
Code:
cpan
install parent
q
yum install ImageMagick ImageMagick-devel
yum remove ImageMagick ImageMagick-devel
# Later when upgrading, you can start here:
Code:
cd /root
wget http://www.imagemagick.org/download/ImageMagick-6.8.5-8.tar.gz
tar zxf ImageMagick-6.8.5-8.tar.gz
cd ImageMagick-6.8.5-8
./configure --with-perl=/usr/bin/perl
make
make install
cd /
ldconfig
cd /root
rpm -i --nodeps http://www.imagemagick.org/download/linux/CentOS/x86_64/ImageMagick-devel-6.8.5-8.x86_64.rpm

# for mod_ruid2 I use (for suphp, see guide):
export PATH=$PATH:/usr/local/bin

cd /root
wget http://pecl.php.net/get/imagick-3.1.0RC2.tgz
tar zxf imagick-3.1.0RC2.tgz

# Edit the file: /root/imagick-3.1.0RC2/config.m4 by changing line number 55 wich looks like this:

if test -r $WAND_DIR/include/ImageMagick/wand/MagickWand.h; then
# change it to look like this:
if test -r $WAND_DIR/include/ImageMagick-6/wand/MagickWand.h; then

# Please note that ImageMagick is changed in above line to be ImageMagick-6, it might be different on your system, navigate to /usr/local/include/ and find the ImageMagick folder to see what version number it has in folder name, and use that folder name in above line number 55.

cd imagick-3.1.0RC2
phpize
./configure
make
make install

# add this to php.ini:
extension=imagick.so

ldconfig
service httpd restart
yum remove ImageMagick-devel

# then you can also delete everything related to imagemagick in /root folder
Do testing:
Create a .php file that has this content (and then visit the page in a browser to see it correct display a path):
Code:
<?php
echo "<pre>";
system("which convert"); 
echo "</pre>";
?>
More testing from command line:

Code:
php -m | grep imagick

identify -version

which convert

/usr/local/bin/identify -list format

/usr/local/bin/identify -list configure

cd /root
/usr/local/bin/convert logo: logo.gif
 

ericovk

Verified User
Joined
Apr 17, 2012
Messages
219
Location
Rotterdam, Netherlands
When I tried to install ImageMagick-6.8.6-4 ( make install ), I bumped into this error:
Code:
make[5]: *** No rule to make target '/usr/lib64/perl5/CORE/thrdvar.h', need 'Q16.o'.  Stopped.
I fixed the problem by downloading thrdvar.h directly from Cpan: cpansearch.perl.org/src/JHI/perl-5.8.0/thrdvar.h
After that I was able to continue with the install. Thanks for creating this post, it really helped :cool:
 

ericovk

Verified User
Joined
Apr 17, 2012
Messages
219
Location
Rotterdam, Netherlands
ImageMagick seems to be installed, but some tests are failing.
When I run the tests as ditto mentioned in post #16, the command line tests are going well. But when I past the php code inside a php file, I get the error:
Code:
[B]Warning[/B]:  system() has been disabled for security reasons in [B]/home/<account>/domains/... on line ..[/B]
I am currently updating centos via yum and directadmin, but what else can I do?
 

ditto

Verified User
Joined
Apr 27, 2009
Messages
2,463
I think you have added system to disable_functions in your php.ini, to run that test, remove "system" from disable_functions in php.ini, and then restart httpd. If you like you can add back "system" in php.ini after you have tested.
 
Top