Instalar ImageMagick e imagick con MAMP en OS X 10.6.4

Hola afición!

MAMP permite gestionar de forma muy cómoda Apache, MySQL y PHP. Necesitaba añadir la extensión imagick, librería de ImageMagick para PHP y después de mucho cruce de información y muchas pruebas lo he conseguido para este entorno de trabajo:

  • MacOS X 10.6.4
  • XCode 3.2.1 y 3.2.2
  • Arquitectura Intel
  • MAMP 1.9.4 (MAMP Pro) con PHP 5.3.2

MAMP 1.9.4 corre Apache 2, MySQL 5.1, PHP 5.2.13 o 5.3.2. Yo estoy corriendo la versión 5.3.2 de PHP para aprovecharme de sus nuevas librerías. El PHP de MAMP permite añadir librerías PECL para instalar casi cualquier extensión a PHP, como imagick para este caso particular.

Paso a paso para añadir la extensión PECL imagick a MAMP 1.9+

1. Instalar y actualizar las XCode de Apple, como mínimo la versión 3.2.1. Este procedimiento es útil para la 3.2.1 y la 3.2.2

2. Instalar MacPorts, desarrollo de una comunidad colaborativa de la red que hace más sencillo compilar, instalar y actualizar aplicaciones que a través de la línea de comandos, la aveces temida shell, pero que siempre es nuestra amiga.

3. Comprobar si la instalación de MacPorts no ha añadido al path del sistema las rutas a sus binarios (/opt/local/bin).

cat ~/.profile

Si devuelve algo como:

# MacPorts Installer addition on 2010-10-25_at_12:30:54: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

no es necesario añadir las rutas, y puedes pasar al punto 4.

Si no ves estas líneas, debes añadir al path del sistema las rutas a los binarios de MacPorts. Editar el fichero profile de tu usuario:

vi ~/.profile

añadir al final:

export PATH="/opt/local/bin:$PATH"

guardar y cerrar (:wq)

Cierra Terminal y vuelve a abrirlo para que tome los nuevos path de entorno de sistema.

4. Actualizar el repositorio local de paquetes de MacPorts, ejecutar en Terminal

sudo port -v selfupdate

5. Editar el fichero variants.conf que ha creado la instalación de MacPorts para que obligue la compilación de paquetes a hacerlos con distribuciones Universal para OS X. Editar:

vi /opt/local/etc/macports/variants.conf

al final del fichero, añadir:

+universal

guardar y salir

:wq

5. Instalar ImageMagick con MacPorts

sudo port install ImageMagick

Con esto, llega el momento de un descanso, porque tarda un buen rato en descargar, compilar e instalar si antes no tenías nada instalado.

Una vez instalado y que no haya dado errores, probar si ImageMagick está bien instalado, ejecutando:

convert -version

debería devolver la versión de ImageMagick instalada, si no, revisa que no te hayas saltado ningún paso.

6. Modificar el fichero envvars de MAMP

vi /Applications/MAMP/Library/bin/envvars

Comentar:

#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH

Añadir:

export PATH="$PATH:/opt/local/bin"

7. Si es necesario, añadir permisos de ejecución a los comandos PHP de MAMP. Puede que necesitemos propagar permisos a los binarios PHP de MAMP, por seguridad vienen sin permisos de ejecución:

sudo chmod +x /Applications/MAMP/bin/php5.3/bin/*

8. Crear el directorio include en el php de MAMP

mkdir /Applications/MAMP/bin/php5.3/include

permisos:

sudo chmod -R 775 /Applications/MAMP/bin/php5.3/include/

9. Descargar el código fuente de la última versión estable de PHP 5 desde:

http://www.php.net/downloads.php

Descomprimir en:

/Applications/MAMP/bin/php5.3/include/

Renombrar el directorio a solo ‘php’, tiene que quedar:

/Applications/MAMP/bin/php5.3/include/php/

10. Hacer el configure de la distribución php descargada

cd /Applications/MAMP/bin/php5.3/include/php/
./configure

11. Una vez hecho el configure, ir hasta el directorio de binarios de php5.3 de MAMP

cd /Applications/MAMP/bin/php5.3/bin/

12. Instalar la extensión PECL imagick. Este punto es común para cualquier otra extensión PECL que querramos añadir a nuestro OS X 10.6.4. Ejecuta:

sudo MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' /Applications/MAMP/bin/php5.3/bin/pecl install imagick

cuando te pida el directorio ImageMagick:

/opt/local

Como ves, compilamos la extensión para la arquitectura -i386 que es compatible con el conjunto sistema operativo y MAMP de 32bit y 64bit.

13. Copiar la extensión imagick.so en la carpeta de extensiones de MAMP

sudo cp /usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/

9. Editar el fichero php.ini de MAMP, desde el menú File -> Edit Templates -> PHP 5.3.2 php.ini. Añadimos en la carga de extensiones dinámicas, al final de esa lista, la de imagick:

extension=imagick.so

Guardamos cambios (Cmd-S) en MAMP.

10. Parar y arrancar MAMP para que refresque la configuración de php.ini

Y eso es todo, a disfrutar nuestro MAMP Pro 1.9.4 y las extensiones PECL.

Bibliografía para todo esta maraña de pruebas:

Installing Image Magick and Imagick for PHP for MAMP, by Adam Stacey
Install MacPorts
Getting MAMP 1.9 to work with Image Magick, imagick.so and other flora
How to enable PECL uploadprogress extention in MAMP
MAMP & Imagick on Snow Leopard

NOTA: Actualizado desde una instalación desde cero. Es un paso a paso, que si no te lo saltas funciona a la perfección.

SaludoX

16 comentarios

  • Este proceso SOLO funciona si los usuarios que corren Apache/MySQL de MAMP Pro son el usuario administrador de tu OS X (osx_user/osx_user), pero da error imagick si quien ejecuta Apache y MySQL de MAMP es www/mysql.

    Hasta tener una solución definitiva, iré haciendo comentarios en voz alta.

  • Hi, I followed all the steps, but now I can’t start up Apache anymore..
    In the log I found:
    [Sun Nov 21 12:01:49 2010] [notice] caught SIGTERM, shutting down
    dyld: lazy symbol binding failed: Symbol not found: _MagickWandGenesis
    Referenced from: /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/imagick.so
    Expected in: flat namespace

    dyld: Symbol not found: _MagickWandGenesis
    Referenced from: /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/imagick.so
    Expected in: flat namespace

    Do you have any idea what this could be?
    I am on OSX 10.6.4, MAMP PRO 1.9.4 with PHP 5.3.2
    Thanks for your blogpost about this subject.

    Anton

  • Are you sure install PECL php5-imagick extension with prevoiusly commad ‘sudo MACOSX_DEPLOYMENT_TARGET=10.6 ….’?

    If you recompile PECL extension, Apache’s run?
    You can try configure/make/make install the php5-imagick extension from http://pecl.php.net/package/imagick PECL 3.0.1, with the deployment target 10.6, too.

    Get luck

  • And… are you sure you have installed XCode 3.2.1 or more installed? Update your gcc via XCode

  • Hi again and thanks for the support.
    Yes I have XCode 3.2.2 installed.
    I think the problem is the libraries used to build ImageMagick.
    I did
    $ sudo port -v selfupdate
    from other tutorials before I added
    $ +universal

    Here are some lines from the Terminal when building imagick:

    ld: warning: in /opt/local/lib/libMagickWand.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libbz2.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libz.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libMagickCore.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/liblcms.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libtiff.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libjpeg.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libfontconfig.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libexpat.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libfreetype.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libiconv.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
    ld: warning: in /opt/local/lib/libltdl.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

    When I do
    $ file imagick.so
    imagick.so: Mach-O universal binary with 2 architectures
    imagick.so (for architecture i386): Mach-O bundle i386
    imagick.so (for architecture x86_64): Mach-O 64-bit bundle x86_64

  • Before ports installation, edit variants.conf file:
    vi /opt/local/etc/macports/variants.conf
    add +universal, save and close.

    You can try:
    1. Reinstall all ports and MacPorts (uninstall and ‘rm’ all files)
    2. Install again

    3. Don’t install ImageMagick 6.6.5, try the 6.6.3-9 version via svn. This is the mini-howto… in spanish sorry:

    sudo port install subversion

    sudo port uninstall php5-imagick
    sudo port uninstall imagemagick

    cd ~/Downloads/im/
    svn co -r 71219 http://svn.macports.org/repository/macports/trunk/dports/graphics/ImageMagick

    cd ~/Downloads/im/ImageMagick/
    sudo port install

    cd ~/Downloads/php5imagick/
    svn co -r 54675 http://svn.macports.org/repository/macports/trunk/dports/php/php5-imagick

    cd ~/Downloads/php5imagick/php5-imagick/
    sudo port install +imagemagick663

    $ convert -version
    Version: ImageMagick 6.6.3-9 2010-11-17 Q16 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
    Features: OpenMP

    If ImageMagick convert -version is 6.6.5, execute:
    sudo port activate ImageMagick @6.6.3-9_1+q16+universal

    Tell me you feedback, please ;-)

  • Hi again, I worked it out, finally. Like I thought the libraries where not +universal. Now all is fine. Thanks for your post.
    All the best!

  • Oh, damn, my last post refreshed the page and I see your note about not using ImageMagick 6.6.5.
    What is the reason for using v6.6.3-9 instead?

  • Only use 6.6.3-9 if imagick (MagickWand) take some errors on php.

    For my develop with clip path, the 6.6.5 don’t work fine, 6.6.3-9 is better.

  • Gracias for the instructions (sorry this is in English). Wanted to let you know this page helped the best (among the tons of posts on the Internet that relate to this issue).

    I was trying these instructions for my old 1.8 MAMP (php5.2) but it wasn’t working. I believe it has to do with the fact that built-in php on OS X is 5.3. The pecl installation I think is using the php source from built-in OS X but I’m not sure.

    At any rate I effectively switched to MAMP php5.3 as opposed to php5.2 and everything works fine.

    If you had any input on how I might try to hack a way to compile imagick (or ssh2, or svn, etc) against 5.2 I’d be interested in knowing how. I tried compiling 5.2 directly on my machine from php.net sources but I’m getting some errors. And even if I was successful or only need to tell pecl to use those sources I’m not sure how I might do that. If I find a way I’ll make another response.

    Otherwise thanks again for the posting.

    e

  • Hi Emmet,

    For PECL installations try the full path ‘/Applications/MAMP/bin/php5.3/bin/pecl install anyone’ or php5.2 ;-) for exclude the buit-in php in OSX

    I tried this installation for MAMP php 5.2 and 5.3. Some pecl extensions require older versions, like Imagick, any comments before ( http://bit.ly/gpky73 ) via subversion

    You can try e new instalaltion of Mamp 1.8 (Reinstall MacPorts and all ports, MAMP 1.8). Then it should work, I think

  • [...] Con las versiones actualizadas de sistema operativo, MAMP, MacPorts e ImageMagick es posible correr Apache y PHP con los usuarios www y mysql desde MAMP sin el menor sobresalto. No como en versiones anteriores y todos los problemas ya conocidos y tratados en mi mensaje Instalar ImageMagick e imagick con MAMP en OS X 10.6.4. [...]

  • Here is a full tutorial, how to install it:
    http://drupal.org/node/1464236

  • Gracias! Hizo mi día…

  • Thanks, I don’t know what exactly solved my problem but it was definitely something I did that you suggested!

    Muchas gracias :)

  • Hi Mau,
    It’s amazing :-)

    you’re welcome!

Deja tu comentario