Installing ImageMagick & Imagick PHP Extension On Dreamhost
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:
1 2 3 4 5 6 |
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz tar zxvf ImageMagick.tar.gz cd ImageMagick-<version> ./configure --prefix=$HOME/local -with-gslib --with-gs-font-dir=/usr/share/fonts/type1/gsfonts/ --without-perl make make install |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
#!/bin/sh # Script updated 2008-09-23 by Skwerl (antiquiet.com) to work with dreamhost's debian etch # Script updated 2007-11-24 by Andrew (ajmconsulting.net) to allow 3rd wget line to pass # Script updated 2006-12-25 by Carl McDade (hiveminds.co.uk) to allow memory limit and freetype # # LIBMCRYPT version information (was set as static download file name previously.) # # Save the code to a file as *.sh # Abort on any errors # set -e # The domain in which to install the PHP CGI script. export DOMAIN="DOMAIN.TLD" # Where do you want all this stuff built? I'd recommend picking a local # filesystem. # ***Don't pick a directory that already exists!*** We clean up after # ourselves at the end! SRCDIR=${HOME}/source # And where should it be installed? INSTALLDIR=${HOME}/php5 # Set DISTDIR to somewhere persistent, if you plan to muck around with this # script and run it several times! DISTDIR=${HOME}/dist # Pre-download clean up!!!! rm -rf $SRCDIR $DISTDIR # Update version information here. PHP5="php-5.2.17" LIBICONV="libiconv-1.11" LIBMCRYPT="libmcrypt-2.5.7" LIBXML2="libxml2-2.6.32" LIBXSLT="libxslt-1.1.24" MHASH="mhash-0.9.7.1" ZLIB="zlib-1.2.5" CURL="curl-7.14.0" LIBIDN="libidn-0.6.8" CCLIENT="imap-2004g" CCLIENT_DIR="imap-2004g" # Another pest! FREETYPE="freetype-2.2.1" OPENSSL="openssl-0.9.8i" # What PHP features do you want enabled? PHPFEATURES="--prefix=${INSTALLDIR} \ --with-config-file-path=${INSTALLDIR}/etc/php5/${DOMAIN} \ --enable-fastcgi \ --enable-force-cgi-redirect \ --with-xml \ --with-libxml-dir=${INSTALLDIR} \ --with-freetype-dir=${INSTALLDIR} \ --enable-soap \ --with-openssl=${INSTALLDIR} \ --with-mhash=${INSTALLDIR} \ --with-mcrypt=${INSTALLDIR} \ --with-zlib-dir=${INSTALLDIR} \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-gd \ --enable-gd-native-ttf \ --enable-memory-limit \ --enable-ftp \ --enable-exif \ --enable-sockets \ --enable-wddx \ --with-iconv=${INSTALLDIR} \ --enable-sqlite-utf8 \ --enable-calendar \ --with-curl=${INSTALLDIR} \ --enable-mbstring \ --enable-mbregex \ --enable-bcmath \ --with-mysql=/usr \ --with-mysqli \ --without-pear \ --with-gettext \ --with-imap=${INSTALLDIR} \ --without-imap-ssl" # ---- end of user-editable bits. Hopefully! ---- # Push the install dir's bin directory into the path export PATH=${INSTALLDIR}/bin:$PATH # set up directories mkdir -p ${SRCDIR} mkdir -p ${INSTALLDIR} mkdir -p ${DISTDIR} cd ${DISTDIR} # Get all the required packages wget -c http://us.php.net/get/${PHP5}.tar.gz/from/this/mirror mv mirror ${PHP5}.tar.gz wget -c http://mirrors.usc.edu/pub/gnu/libiconv/${LIBICONV}.tar.gz wget -c ftp://ftp.uni-weimar.de/pub/unix/${LIBMCRYPT}.tar.gz wget -c http://xmlsoft.org/sources/old/${LIBXML2}.tar.gz wget -c http://xmlsoft.org/sources/${LIBXSLT}.tar.gz wget -c http://iweb.dl.sourceforge.net/project/mhash/mhash/0.9.7.1/${MHASH}.tar.gz wget -c http://www.zlib.net/${ZLIB}.tar.gz wget -c http://curl.haxx.se/download/${CURL}.tar.gz wget -c http://kent.dl.sourceforge.net/sourceforge/freetype/${FREETYPE}.tar.gz wget -c ftp://alpha.gnu.org/pub/gnu/libidn/${LIBIDN}.tar.gz wget -c ftp://ftp.cac.washington.edu/imap/old/${CCLIENT}.tar.Z wget -c http://www.openssl.org/source/${OPENSSL}.tar.gz echo ---------- Unpacking downloaded archives. This process may take several minutes! ---------- cd ${SRCDIR} # Unpack them all echo Extracting ${PHP5}... tar xzf ${DISTDIR}/${PHP5}.tar.gz echo Done. echo Extracting ${LIBICONV}... tar xzf ${DISTDIR}/${LIBICONV}.tar.gz echo Done. echo Extracting ${LIBMCRYPT}... tar xzf ${DISTDIR}/${LIBMCRYPT}.tar.gz echo Done. echo Extracting ${LIBXML2}... tar xzf ${DISTDIR}/${LIBXML2}.tar.gz echo Done. echo Extracting ${LIBXSLT}... tar xzf ${DISTDIR}/${LIBXSLT}.tar.gz echo Done. echo Extracting ${MHASH}... tar xzf ${DISTDIR}/${MHASH}.tar.gz echo Done. echo Extracting ${ZLIB}... tar xzf ${DISTDIR}/${ZLIB}.tar.gz echo Done. echo Extracting ${CURL}... tar xzf ${DISTDIR}/${CURL}.tar.gz echo Done. echo Extracting ${LIBIDN}... tar xzf ${DISTDIR}/${LIBIDN}.tar.gz echo Done. echo Extracting ${CCLIENT}... uncompress -cd ${DISTDIR}/${CCLIENT}.tar.Z |tar x echo Done. echo Extracting ${FREETYPE}... tar xzf ${DISTDIR}/${FREETYPE}.tar.gz echo Done. echo Extracting ${OPENSSL}... tar xzf ${DISTDIR}/${OPENSSL}.tar.gz echo Done. # Build them in the required order to satisfy dependencies. #libiconv cd ${SRCDIR}/${LIBICONV} ./configure --enable-extra-encodings --prefix=${INSTALLDIR} # make clean make make install #libxml2 cd ${SRCDIR}/${LIBXML2} ./configure --with-iconv=${INSTALLDIR} --prefix=${INSTALLDIR} # make clean make make install #libxslt cd ${SRCDIR}/${LIBXSLT} ./configure --prefix=${INSTALLDIR} \ --with-libxml-prefix=${INSTALLDIR} \ --with-libxml-include-prefix=${INSTALLDIR}/include/ \ --with-libxml-libs-prefix=${INSTALLDIR}/lib/ # make clean make make install #zlib cd ${SRCDIR}/${ZLIB} ./configure --shared --prefix=${INSTALLDIR} # make clean make make install #libmcrypt cd ${SRCDIR}/${LIBMCRYPT} ./configure --disable-posix-threads --prefix=${INSTALLDIR} # make clean make make install #libmcrypt lltdl issue!! cd ${SRCDIR}/${LIBMCRYPT}/libltdl ./configure --prefix=${INSTALLDIR} --enable-ltdl-install # make clean make make install #mhash cd ${SRCDIR}/${MHASH} ./configure --prefix=${INSTALLDIR} # make clean make make install #freetype cd ${SRCDIR}/${FREETYPE} ./configure --prefix=${INSTALLDIR} # make clean make make install #libidn cd ${SRCDIR}/${LIBIDN} ./configure --with-iconv-prefix=${INSTALLDIR} --prefix=${INSTALLDIR} # make clean make make install #cURL cd ${SRCDIR}/${CURL} ./configure --with-ssl=${INSTALLDIR} --with-zlib=${INSTALLDIR} \ --with-libidn=${INSTALLDIR} --enable-ipv6 --enable-cookies \ --enable-crypto-auth --prefix=${INSTALLDIR} # make clean make make install # c-client cd ${SRCDIR}/${CCLIENT_DIR} make -i ldb SSLTYPE=none # Install targets are for wusses! cp c-client/c-client.a ${INSTALLDIR}/lib/libc-client.a cp c-client/*.h ${INSTALLDIR}/include #OpenSSL cd ${SRCDIR}/${OPENSSL} ./config --prefix=${INSTALLDIR} --openssldir=${INSTALLDIR} make make install echo - about to build php5... echo read -p "(Press any key to continue)" temp; echo #PHP 5 cd ${SRCDIR}/${PHP5} ./configure ${PHPFEATURES} # make clean make make install #copy config file mkdir -p ${INSTALLDIR}/etc/php5/${DOMAIN} cp ${SRCDIR}/${PHP5}/php.ini-dist ${INSTALLDIR}/etc/php5/${DOMAIN}/php.ini #copy PHP CGI mkdir -p ${HOME}/${DOMAIN}/cgi-bin chmod 0755 ${HOME}/${DOMAIN}/cgi-bin cp ${INSTALLDIR}/bin/php ${HOME}/${DOMAIN}/cgi-bin/php.cgi rm -rf $SRCDIR $DISTDIR echo ---------- INSTALL COMPLETE! ---------- |
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.
1 2 3 4 5 6 7 8 9 |
Options +ExecCGI AddHandler php-cgi .php Action php-cgi /cgi-bin/php.cgi <FilesMatch "^php5?\.(ini|cgi)$"> Order Deny,Allow Deny from All Allow from env=REDIRECT_STATUS </FilesMatch> |
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).
1 |
cp ~/php5/bin/php-cgi ~/DOMAIN.TLD/cgi-bin/php.cgi |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
mkdir ~/source cd ~/source wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.63.tar.gz tar xzf autoconf-2.63.tar.gz cd autoconf-2.63 ./configure --prefix=$HOME/source nice -n 19 make make install export PATH=/home/{username}/source/bin:$PATH cd ~/ wget http://pecl.php.net/get/imagick-2.2.2.tgz tar zxvf imagick-2.2.2.tgz cd imagick-2.2.2 phpize ./configure -prefix=$HOME/imagick --with-imagick=$HOME/local --with-php-config=$HOME/php5/bin/php-config make make install |
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.
1 2 |
cd ~/ vi ~/php5/etc/php5/DOMAIN.TLD/php.ini |
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
Pat
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.
Veneficus Unus
Thanks for that. I didn’t need TIFF support so I never realised that. Hopefully you’ve just helped anyone who needs it. 😀
Prince Thomas
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
Paul Robinson
No problem, glad we were able to help you. 🙂
Michael Montoya
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?
Michael Montoya
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?
Paul Robinson
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.
Mark
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.
Paul Robinson
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.
mark
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
Paul Robinson
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.
Mark
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
Paul Robinson
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.
milan
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
Paul Robinson
Sorry Milan, I honestly have no idea. I haven’t yet had a chance to try on PHP 5.3.5. Is there nothing on the Dreamhost wiki at http://wiki.dreamhost.com?
milan
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
Paul Robinson
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.
milan
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 🙂
Paul Robinson
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.
Jake
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
Paul Robinson
Thanks Jake,
If you don’t mind, I’ll update the code in the post with your version. 🙂
theengineeredbusiness.com
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.
andrettisan
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!
Paul Robinson
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.