MAMP & Imagick on Snow Leopard
Most web searches for adding the imagick extension to MAMP suggest using MacPorts to install ImageMagick and then use this compiled version as the library to running ‘pecl install imagick’.
As I was in the process of setting up a clean Mac Book Pro, I tried going through this process. I quickly ran into some problems getting the imagick extension running under MAMP. This is a tail of that adventure.
I started with the latest version of MAMP 1.8.4 and MacPorts 1.8.2 installed.
Then installed ImageMagick
$ sudo port install ImageMagick
This went off without a problem. Could then easily run the ‘convert’ program to see if is working. Next step felt like to install imagick extension.
$ cd /Applications/MAMP/bin/php5/bin
And just make sure the right version of PECL is executed via ‘./’ else may get Mac OS X installed or even MacPorts installed version.
$ ./pecl install imagick
The process doesn’t stop with error, but immediately it has gripes about missing header files.
downloading imagick-2.3.0.tgz ...
Starting to download imagick-2.3.0.tgz (86,976 bytes)
.....................done: 86,976 bytes
12 source files, building
WARNING: php_bin /Applications/MAMP/bin/php5/bin/php appears to have a suffix 5/bin/php, but config variable php_suffix does not match
running: phpize
grep: /Applications/ MAMP/bin/php5/include/php/main/php.h: No such file or directory
grep: /Applications/ MAMP/bin/php5/include/php/Zend/zend_modules.h: No such file or directory
grep: /Applications/ MAMP/bin/php5/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
configure.in:158: warning: AC_CACHE_VAL(lt_prog_compiler_static_works, ...): suspicious cache-id, must contain _cv_ to be cached
../../lib/autoconf/general.m4:1998: AC_CACHE_VAL is expanded from...
...
aclocal.m4:4641: _LT_AC_TAGCONFIG is expanded from...
Please provide the prefix of Imagemagick installation [autodetect] :
$
The first problem encountered was simply getting ‘pecl’ to compile the imagick extension as the MAMP distribution does not include the php headers where pecl is expecting them.
There is probably a way to get pecl to pick them up properly, but in the interest of time, one can just create a link from
$ cd /Applications/MAMP/bin/php5
$ ln -s /Applications/MAMP/Library/include include
And then re-run ‘pecl’
$ ./pecl install imagick
...
Please provide the prefix of Imagemagick installation [autodetect] : /opt/local
building in /var/tmp/pear-build-mleo/imagick-2.3.0
running: /private/tmp/pear/temp/imagick/configure --with-imagick=/opt/local
...
and provide ‘/opt/local’ when prompted for prefix of Imagemagick installation. Everthing seemed to go well. Finally, modified /Applications/MAMP/conf/php5/php.ini to add
extenstion=imagick.so
And modified /Applications/MAMP/Library/bin/envvars to add
DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:/opt/local/lib:$DYLD_LIBRARY_PATH"
Finally ran:
$ /Applications/MAMP/bin/php5/bin/php -i | less
to see if it was enabled. Unfortunately, the imagick module was not listed. After a little investigation, in the php error log was the following entry:
PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so' - (null) in Unknown on line 0
After some various searching and other, checking what I did wrong, I finally considered the files:
$ file /Applications/MAMP/bin/php5/bin/php
/Applications/MAMP/bin/php5/bin/php: Mach-O universal binary with 2 architectures
/Applications/MAMP/bin/php5/bin/php (for architecture ppc): Mach-O executable ppc
/Applications/MAMP/bin/php5/bin/php (for architecture i386): Mach-O executable i386
$ file /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so (for architecture x86_64): Mach-O 64-bit x86_64
So discovered that MAMP is a Universal binary, just not an x86_64 universal binary. So, first, make sure to rebuild imagick.so with i386 binary support and just to be safe, add those settings for the php header files as well.
So, back to the php distribution and run configure setting some flags, although this may not be needed, it can’t hurt.
$ MACOSX_DEPLOYMENT_TARGET=10.6 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" ./configure --enable-shared
loading cache ./config.cache
checking for Cygwin environment... (cached) no
...
Copy the headers back to MAMP location. And re-run pecl to build universal binary.
$ ./pecl uninstall imagick
$ MACOSX_DEPLOYMENT_TARGET=10.6 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
Run php printinfo and
$ /Applications/MAMP/bin/php5/bin/php -i | less
dyld: NSLinkModule() error
dyld: Library not loaded: /opt/local/lib/libMagickWand.2.dylib
Referenced from: /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/imagick.so
Reason: no suitable image found. Did find:
/opt/local/lib/libMagickWand.2.dylib: mach-o, but wrong architecture
And discover that MacPorts isn’t creating universal binaries.
$ file /opt/local/lib/libMagickCore.2.dylib
/opt/local/lib/libMagickCore.2.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Again, head to the favorite search engine and look at how MacPorts can work with Universal binaries. After some criteria changes came across this simple set of details.
MacPorts provides a variant +universal for all installs that use configure script to initialize build process that will build Universal binaries. The specific architecture has some defaults based on the OS and current hardware.
A bit of pain to add +universal to every port install command, so make +universal, uh, universal it can be added to the /opt/local/etc/macports/variants.conf file as last line:
# To specify global variants to use for all port builds,
# customize this file to list variant settings you want.
#
# Be sure to uncomment/define the variants_conf setting
# in the system wide ${prefix}/etc/macports/macports.conf
# file or in your personal ~/.macports/macports.conf to
# point to this file to enable this feature.
#
# Any variants specified here that are not supported by
# a port will just be ignored. Multiple variants can be
# specified per line, or one per line is also allowed.
#
# Example:
# +ipv6 +no_x11
+universal
And to force a rebuild of anything you have installed
sudo port upgrade --force installed
Finally, we try php again:
$ /Applications/MAMP/bin/php5/bin/php -i | less
...
imagick
imagick module => enabled
imagick module version => 2.3.0
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
ImageMagick version => ImageMagick 6.5.8-0 2010-01-05 Q16 http://www.imagemagick.org
ImageMagick copyright => Copyright (C) 1999-2009 ImageMagick Studio LLC
ImageMagick release date => 2010-01-05
ImageMagick Number of supported formats: => 194
ImageMagick Supported formats => 3FR, A, AI, ART, ARW, AVI, AVS, B, BGR, BMP, BMP2, BMP3, BRF, BRG, C, CAL, CALS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DCM, DCR, DCX, DDS, DFONT, DNG, DOT, DPX, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FITS, FRACTAL, FTS, G, G3, GBR, GIF, GIF87, GRADIENT, GRAY, GRB, GROUP4, HALD, HISTOGRAM, HRZ, HTM, HTML, ICB, ICO, ICON, INFO, INLINE, IPL, ISOBRL, JNG, JPEG, JPG, K, K25, KDC, LABEL, M, M2V, M4V, MAP, MAT, MATTE, MIFF, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NULL, O, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PFA, PFB, PFM, PGM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG24, PNG32, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RBG, RGB, RGBA, RGBO, RLA, RLE, SCR, SCT, SFW, SGI, SHTML, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UIL, UYVY, VDA, VICAR, VID, VIFF, VST, WBMP, WMV, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, Y, YCbCr, YCbCrA, YUV
Directive => Local Value => Master Value
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
...
Somewhere during this adventure I definitely considered dumping MAMP and using apache, php and mysql from MacPorts but MAMP does generally provide a simple package installation and a GUI for quickly starting and stopping the services.