Installing Image Magick and Imagick for PHP for MAMP
Now this is one topic I am glad I have got through. This caused me no end of grief.
I think before we get to the nitty gritty of installing and configuring the software it is important to understand what Image Magick and Imagick are. I thought at first it was the same thing. Oh how wrong!
Image Magick is a command-line suite of tools to manipulate images. For further information on this visit the Image Magick site.
Imagick is an extension of PHP that consists of a number of classes and functions for working with Image Magick.
It basically means we need to install Image Magick first and then compile the Imagick extension in PHP that is dependent on Image Magick.
1. Installing MacPorts
To make life easy I installed MacPorts, which made it very easy to install Image Magick. You will need MacPorts in order to follow this post. Don’t worry if you haven’t installed MacPorts yet as you can find out how easy it is to install by viewing my “Installing MacPorts” post.
Please note that if you have Mac OS X 10.5.x or later you need to have Xcode 3.1.4 installed or later.
EDIT: Big thank you to Mike Puchol and his article Getting MAMP 1.9 to work with Image Magick, imagick.so and other flora for the next snippet for making MacPorts build universal binaries.
vi /opt/local/etc/macports/variants.conf
Add the following to the end of the file:
+universal
Save the file:
?wq
2. Installing Image Magick
Using MacPorts we simply need to enter:
sudo port install ImageMagick
Now I would suggest putting your feet up, grab something to eat, grab a beer or something else more interesting as this process takes about 30 minutes to finish. There are a number of dependencies that have to be installed.
Here’s One I Prepared Earlier…
Once that is all sorted you then need to update the environment $PATH variable in your user profile. To access your profile enter:
vi ~/.profile
Enter the following line:
export PATH="$PATH:/opt/local/bin"
For more information on this see “Updating Your Export Path in OS X”.
Close terminal and re-open it again. Then test Image Magick to see if it is working:
convert -version
If you get an error then there is a problem. Drop me a comment and I will see what I can do.
3. Now Installing The Tricky Imagick!
We now need to install the Imagick extension using PECL:
sudo pecl install imagick
Is that it I hear you say? Well let me tell you that it is at this point where I lost my rag given all the problems I had. I had got so lost I even nearly turned to the dark side and tried searching on Bing! To try and help I have added the issues I had and what I did to sort them.
A Make Error Occurs
I found this issue is likely to be down to the C compiler not being present. You will notice that there is an error relating to this, but it is right at the beginning of the make output. The easiest way to check if you have the C compiler is to type:
gcc
If you get a bash error then it is not installed. You can also check to see if the /usr/bin/gcc folder exists as that is where it should be.
So, to fix this issue you simply need to install the Xcode Tools. The quickest way to do this is on the installation disc that came with your Mac. It will be under the optional installs. If you can’t find the installation disc you can download the latest Xcode tools from the Apple Developer Connection site.
32bit and 64bit Architecture
As standard, MacPorts will not build universal binaries, which is what the PHP version run by MAMP uses. And as some versions of Mac OS X like Snow Leopard use 64bit architecture this can cause an issue. To get round this you can force MacPorts to build all the universal binaries by entering:
sudo port upgrade --force installed
Like installing Image Magick this will take a bit of time, so kick back and relax.
WARNING: php appears to have a suffix…
This is due to the PHP path being referenced twice or more in the environment variable $PATH. This is probably due to the /usr/bin and /Applications/MAMP/bin/php5.3/bin folders being present when they effectively point to the same place. You just need to remove the MAMP path. Restart terminal and you should be good to go. Don’t forget to check your $PATH enter:
echo $PATH
4. Are We There Yet?
Right, so the install of the Imagick extension has been successful. If so, you should see a message saying where the .so file was installed. You now need to copy that file over to the MAMP files:
cp /usr/lib/php/extensions/no-debug-non-zts-20060613/imagick.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/imagick.so
The above should be similar to yours, but will slightly differ, but you should be able to work it out.
The last bit then. We just need to add the new extension to the php.ini file. In MAMP select File -> Edit Templates and select the php.ini file you are using for your version. In the file add the Imagick extension:
extension=imagick.so
Apply the changes to MAMP, which should restart Apache and MySQL. Job done!!!
It has been emotional! This was a tough one, so if you need any help or have any suggestions just drop me some comments.





There’s one thing that I struggled with, which was that midway thru the “sudo ./pecl install imagick” process, it asked for a prefix for the Imagemagick installation. As noted here: [http://unrealexpectations.com/blog/2010/01/mamp-imagick-on-snow-leopard/], responding with /opt/local seemed to solve the build issues for me.
YMMV, of course.
Hi Joshua,
Thanks for letting me know. I noticed during my hours of researching this issue that others also experienced this. From memory I think the opt/local is the directory that houses anything installed via mac ports, so that would make sense. Glad it all worked for you.
Cheers
[...] Imagemagick (and more) to work with MAMP on OS X – misses info on compiling for Snow Leopard. Installing Image Magick and Imagick for PHP for MAMP – misses change needed in ports conf file to enable Universal mode. MAMP & Imagick on [...]
Blimey. Just got it working. What a ride. Thanks for this post. Helped no end. A few things I came up against (forgive me and please amend if they are incorrect – I am a novice):
Make sure the macports dependencies tree is up to date –
sudo port build tree.Make sure all packages are up to date (I forget the exact command).
The following helped with checksum failures in macports: https://trac.macports.org/ticket/26075
Thanks,
Anthony
Also, php.ini file could be anywhere. I had two, and the one I needed was in /private/etc/php.ini.
If you’re editing one and it’s making no difference, use
sudo find / -name php.inito find them all, and mess with them until php breaks. Not sure if a server restart was required each time (I think not) but I did it anyway.Yes, that is a good point. I made the assumption that there would be one. Many people will have more than one php.ini file, so thanks for the info.
I’m glad the article helped and thanks for the advice on the checksum failures in macports.
Hi All
Thanks for these instructions – very helpful – just to add some help after installing this on OS X Lion…
Followed the instructions above – when installing imagick i had to use the following:
sudo MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch i386 -arch x86_64 -bind_at_load” pecl install imagick
I then hit another problem
– it was stating that my /opt/local/lib/libfreetype.6.dylib was not the correct version. After a little bit of searching I found the answer on this post:
http://forum.mamp.info/viewtopic.php?f=2&t=8245
You have to copy the /opt/local/lib/libfreetype.6.dylib and paste it over the version of this file that MAMP has…
Hope this helps
Hi
Thanks for a great post, I’m nearly there but having problems installing the tricky imagick.
If I try ‘sudo peci install imagick’ I get ‘sudo: pecl: command not found’
If I try ‘gcc’ I get ‘i686-apple-darwin10-gcc-4.2.1: no input files’
I have Xcode tools installed.
Any ideas on a next move?
[...] http://thoomtech.com/post/8832473042/mamp-imagemagick-lion http://www.adamstacey.co.uk/2010/06/28/installing-image-magick-and-imagick-for-php-for-mamp/ http://unrealexpectations.com/blog/2010/01/mamp-imagick-on-snow-leopard/ [...]
Thanks man, this helped a lot after over two day of trying to get this to work.
Hi,
Thanks a lot for the tutorial. I have had an issue on step #3 though with installing imagick through pecl. Aparently, looks like it’s looking for a MagickWan-config program inside a wrong location.
This simlink helped.
[CODE]ln -s /opt/local/bin/Wand-config /usr/local/bin/MagickWand-config[/CODE]
Taken from: http://it.works-for-me.net/mac-os-x/2011/08/12/imagemagick-workaround-cannot-locate-configuration-program-magickwand-config/
Sorry for double post, just when I though it’s all over and it should work, in the very last step when I am adding extension to my PHP.ini I get the following error in logs:
“PHP Startup: imagick: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
”
Looks like the API version with which we have compiled the imagik.so is older then PHP 5.4.4, but which part do I update?
[...] Installing Image Magick and Imagick for PHP and MAMP [...]
[...] Installing Image Magick and Imagick for PHP and MAMP [...]
Thanks for this comprehensive article.
It might be worth updating your article to include Joshua’s comment that adding “/opt/local” to the prefix prompt might be needed when using “sudo pecl install imagick”.
Only after lots of searching on Google and time wasted did I spot the comment as I wouldn’t usually read them…. Especially since the error reported “Please provide a path to MagickWand-config or Wand-config program” sounds like it isn’t picking up the PATH variable which we add.
Why doesn’t this site operate in Internet explorer? I had to switch to firefox to read the content. Not a big deal, but annoying for somebody that despises using firefox. I wouldn’t care that much,
but I actually wanted to get more information.