Installing ImageMagick & Imagick PHP Extension On Dreamhost

/ PHP / by Paul Robinson / 26 Comments
This post was published back on February 27, 2009 and may be outdated. Please use caution when following older tutorials or using older code. After reading be sure to check for newer procedures or updates to code.

I have recently been installing ImageMagick on my server for use on my other site Celeb O Rama, but because I am on Dreamhost I can’t just install what I like, like you would on a server that you own. So by using the Dreamhost Wiki I installed ImageMagick, but there are no instructions on how to install Imagick. The following is how to install them both on Dreamhost.

First though it should be noted that if you are using PHP 5.3 there is a much easier way to install IMagick, check out the Dreamhost Wiki for more info. Also if you are using Nginx and PHP 5.2 on Dreamhost you only need to create a file called .php-ini in your home folder with the extra PHP.ini instructions in, again more on the Dreamhost Wiki.

First to install ImageMagick:

Usually you would use --with-perl-options but for some reason versions of ImageMagick after 6.4.5 don’t seem to install perlmagick correctly on Dreamhost’s servers. You don’t really need it when using ImageMagick with PHP anyway.

Onto Installing Custom PHP5

Ok, this is the tricky bit. To install Imagick you need to have a custom PHP installation. If you don’t you won’t be able to install Imagick. The main reason that I come across for this (since you could just make a copy of the PHP.ini instead) is that Dreamhost’s version of php-config, which Imagick uses to find PHP’s version, still says PHP 4 instead of 5.2.5. This means Imagick won’t install since it requires 5.1.2 and up, I think. I know it has to be higher than PHP 5.

So here is how to do it. This is also available from the Dreamhost wiki. Copy the following script which was written by Skwerl. Credits are at the top of the shell script. Oh, and don’t forget to change the domain to the domain you want to use the custom PHP install with:

Copy that into clipboard open an SSH connection & do vi php5-skwerl.sh and paste in the code (press ‘i’ then right click to paste). Then save the file by pressing ESC then :wq (that’s ‘Colon’, ‘w’ then ‘q’) then press enter. Use chmod +x php5-skwerl.sh to make the script executable. Finally run the script using ./php5-skwerl.sh. DO NOT copy the code into notepad & save it then upload it, it’s alot easier to use vi.

During the installation you may get a little message warning about unencrpted passwords, I can’t remember exactly but as long as you don’t want to use openSSL you can either say yes or no. Since I have no use for SSL or openSSL I just said no.

Once the code has finished, it took around 30-40 minutes for me, then you will need to tell your server to use your PHP installation. To do this add this to your .htaccess file.

Then give a PHP page a refresh & see what happens, chances are you’ll get a 500 or Internal Server Error. If you do, don’t panic, just run this from the SSH command line (bash).

Change DOMAIN.TLD to the domain you chose to install the custom PHP installation too. All should be fine after that.

Installing Imagick

Now for the bit which isn’t covered in the Dreamhost wiki. Installing Imagick. It took a little bit of time but I managed to get it installed. You first need to download, compile & install autoconf & then Imagick.

Don’t forget to change {username} on line 9 to your username or you’ll get a error.

Phew! After that it should tell you the path to imagick.so which you need to instuct your PHP.ini to find. So let’s do that. First either write down the path given or copy it to clipboard. In Putty you do that just by highlighting the text in the window.

scroll all the way down until you find extension_dir='./' and change it to the FULL path to the folder given by the build of imagick before. If you have it in clipboard press i then delete ./ and right click. Now find the list of extensions which look like ‘;extension=thing_some.dll’ and after the last one add ‘extension=imagick.so’. Now press ESC then colon ‘w’ ‘q’ and enter to quit and save.

Once you’ve done all that, make a php file with phpinfo() in it and go down and see if you can find this

And Relax

Yup, that’s it. It takes about 1 hour maybe 1 hour 30. It’s worth it if you don’t like to use exec() in your scripts, also Imagick supports PHP’s try, catch exception system so you can easily output nice errors instead of guessing what’s happened when exec fails. For a full list of imagick, imagickDraw, imagickPixel and all the other imagick commands look at php.net.

Hope that helps someone, the instructions can be applied to any server really, but you will need to change certain options since these ones are specifically for Dreamhost since write access to /usr/ is denied for obvious reasons. Any problems or questions feel free to ask.

The shell script & instructions for installing php5 & the info for installing imagemagick have been used from the Dreamhost wiki since they are correct & no modifications need to be made for them to work. Credit for those parts go to the authors from the Wiki. The imagick installation was written by me since no documentation for installing imagick exists in the Dreamhost wiki.

26 Comments

Author’s gravatar

Thanks for the tut! This worked like a charm to get Imagick support working on Dreamhost!

Just a tip for fellow dreamhosters – this method doesn’t not appear to enable TIFF support, if you need it, I’d recommend installing libtiff from source in your home directory and linking the ImageMagick build against it during the first step.

A few other uncommon formats that might require this step: RSVG, JBIG, JPEG-2000, GhostScript – basically a ./configure on your ImageMagick source should tell you what libs were available.

Reply
Author’s gravatar

Thanks for that. I didn’t need TIFF support so I never realised that. Hopefully you’ve just helped anyone who needs it. 😀

Reply
Author’s gravatar

hi guys, thanks you very much for this post.. i am really thank full to you because. i have visited 50 sites but not get any solution for installing imagick library on shared server. but i have done with installed by your help……thank you very much…
Prince Thomas

Reply
Author’s gravatar

Thanks to your instructions I was successfully able to get imagick working on my Dreamhost account. I am, however, experiencing a problem converting .pdf files into images. I’m assuming this has to do with Ghostscript. I have checked the version on DH and they are using 6.2, which should at least work with the current build, however when I try to load a pdf for conversion I get errors. Is there something I need to do to point imagick to the gs? Does imagick require a more recent version of GS?

Reply
Author’s gravatar

I’ll answer my own question here – it seems the particular function I was using is only available in Image Magick 6.3.8 and the version install on DH is 6.3.7. This leads me to ask another question, I did install a current version as per your instructions above, but it seems my install is not getting picked up, how do I point imagick to my local version?

Author’s gravatar author

I actually don’t use imagick any more as I tend to use the cli version instead so I can’t test this out, but the –with-imagick parameter tells imagick where your imagemagick install is. You will need to adjust it if your path is different.

It’s kind of a misnomer, but according to the documentation that is the config option you need to change if imagemagick is installed at a path other than the default system path.

If that doesn’t work or the install paths are the same, I’m not sure? I’ve always found it works okay if you keep the -with–imagick option the same as the prefix used when installing imagemagick.

Author’s gravatar

Hi I need your help. I followed the script and run it from my server and I got this error :


[ps17015]$ ./php5-skwerl.sh
–05:25:29– http://us.php.net/get/php-5.2.5.tar.gz/from/this/mirror
=> `mirror’
Resolving us.php.net… 208.69.120.58
Connecting to us.php.net|208.69.120.58|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
05:25:30 ERROR 404: Not Found.

Hoping for your favorable response.

Reply
Author’s gravatar author

Hi,

The error is exactly what it looks like, php.net no longer host 5.2.5 on their servers. The lowest binary I can find is 5.2.12 so all you need to do is change:

to

and you should be okay.

Hope that helps.

Author’s gravatar

while installing Imagick running the ff lines, I got each result below :

./configure -prefix=$HOME/imagick –with-imagick=$HOME/local –with-php-config=$HOME/php5/bin/php-config

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

make

make: *** No targets specified and no makefile found. Stop.

make install

make: *** No rule to make target `install’. Stop.

Hoping for your soonest and favorable response

Author’s gravatar author

That error would say to me that imagemagick isn’t in the location you have set. Is your MagickWand-config & Wand-config files inside ~/local/bin?

If they are I’m not sure what is going on. I’m no expert on Unix systems, these scripts/commands are just the ones that worked for me on Dreamhost’s systems.

Author’s gravatar

Thank you for this. I have installed it successfully now.

Just one thing, when installing custom php under a domain.tld, will it also be applicable on it’s subdomain like subdomain.domain.tld? Or do I need to install a custom php under the subdomain and how to do it?

Thank You

Author’s gravatar author

No problem.

Re the subdomains, I believe you may need to symbolic link the php binary to the cgi-bin. There should be info on how to do that on the install PHP5 page of the dreamhost wiki here.

Hope that helps.

Author’s gravatar

any idea how to install Imagick on dreamhost with php 5.3.5? It is not the same since php 5.3 has much simpler way of using custom php

Reply
Author’s gravatar

there is how to make custom php and it looks easier. But I didnt managed to make it work with imagick. Check it out and let me know if yo uhave an idea. I need that imagick badly because i am running sponsored photocontest and uploaded photos dont look good with GD library. Need Imagick 🙁

http://wiki.dreamhost.com/PHP.ini

Reply
Author’s gravatar author

I can’t be sure as I haven’t had a chance to try it but it would probably go something like this.

First follow the instructions on the PHP.ini page on Dreamhost for setting up a custom ini file for PHP 5.3. Then try this.

Make sure you change the path on the --with-imagick to the path to your imagemagick install or it won’t work. If using a normal Dreamhost install of Imagemagick it is /usr/bin I believe. Then you would copy the output .so file into your .php/53 directory that you have created for the custom PHP. Then add:

Into the phprc file the Dreamhost wiki told you to make. Obviously replace ‘username’ & ‘mymodule’ with your username & the name of the imagick module respectively.

Hopefully that will work. Again I can’t be sure as I’m not yet ready to upgrade to 5.3, but let me know how it goes if you can.

Author’s gravatar

I did it.
Combined the two instructions. First installed imagemagick like on this page. Then used this link:
http://wiki.dreamhost.com/PHP.ini
to create custom php. Phprc method didnt work. I just copied the original php.ini to .php/5.3/ folder and it automaticaly used that php.ini instead of original. Then I installed imagick using the instructions here and copied imagick.so to .php/5.3/ folder and created a path to imagick.so in my new php.ini and it worked.
Thats it in short 🙂

Author’s gravatar author

Not sure why the phprc didn’t work, but great job on managing to get it working. 🙂

I was hoping it would be similar in some ways to the older way.

Author’s gravatar

Here’s a copy of the script with updated links. I had to change a couple things to get everything to work: http://pastebin.com/eL47HENL

Reply
Author’s gravatar author

Thanks Jake,

If you don’t mind, I’ll update the code in the post with your version. 🙂

Author’s gravatar

If some one needs to be updated with most recent technologies then he must be pay a visit this web site and be up to date
daily.

Reply
Author’s gravatar

Hey guys, first of all thanks for all. I have imagemagick up and running on my server but for now only the command line. I would like to load imagick.so module into php but I can’t even find it on my server. I tried “#locate imagick.so” but no results are shown.
Please tell me where to wget that module and how to load it. I appreciate your comments, thanks!

Reply
Author’s gravatar author

If you don’t have imagick you’ll have to compile it from the PHP PECL directory. You can find how to do it in the last half of this tutorial.

Older Comments
Newer Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I'll keep your WordPress site up-to-date and working to its best.

Find out more