OS X 10.6 (Snow Leopard) – using MAMP/PECL to install PHP extensions

Need help installing PHP extensions for OS X 10.6 (Snow Leopard) using MAMP and the included pecl binary? Well, you have come to the right place. If you have tried this on its own, you will notice that none of the extensions pecl builds will work with MAMP. This is because MAMP is compiled as a 32-bit binary whereas pecl tries to build 64-bit PHP extensions.

[Update Feb. 1, 2011]

A much easier way to install PECL packages:

CFLAGS="-arch i386" ./pecl install

To get pecl working properly, make sure you have Xcode installed on you machine. Next, you will need to get a copy of MAMP’s source and prepare it using 32-bit compile flags. You can download the MAMP source from the MAMP download page. Running the .dmg should extract the source. After extracting the source run the following:


mkdir /Applications/MAMP/Library/Include/
mv /path/to/extracted/mamp/source/ /Applications/MAMP/Library/Include/

Next you will want to extract the PHP package and do the following to prepare the package:


mv /Applications/MAMP/Library/Include/extracted_php_source/ /Applications/MAMP/bin/php5/include/php/
cd /Applications/MAMP/bin/php5/include/php/
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' ./configure --with-php-config=/Applications/MAMP/bin/php5/bin/php-config

Finally, you now can install pecl extensions with the following command:

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/bin/pecl install

And that’s it! Enjoy!

Posted in Computing, Development, OS X, PHP by Andrew Vayanis at May 19th, 2010.
Tags: , , ,

6 Responses to “OS X 10.6 (Snow Leopard) – using MAMP/PECL to install PHP extensions”

  1. Yves says:

    Hi,

    this has been nothing but a nightmare, 2 days and I still haven’t been able to install a pecl package, the only one that has worked was a precompiled one.

    I figure you maybe able to help me out?

    I’m trying intall HttpRequest (pecl_http) I’ve tried both MAMP and XAMPP, done all sorts of trickery through the terminal in order to get it to compile properly, including from what’s on this page, and I keep getting this error when I start MAMP up:-

    [11-Jul-2010 17:37:54] PHP Warning: PHP Startup: Unable to load dynamic library ‘/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/http.so’ – (null) in Unknown on line 0

  2. Are you using Snow Leopard? Also, when you follow the instructions on this page, do you get any warnings or errors?

  3. dale says:

    where are getting the “./configure” file in this statement:

    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′ ./configure –with-php-config=/Applications/MAMP/bin/php5/bin/php-config

    I downloaded the latest mamp build which has php5.3, and there was no “MAMP/bin/php5.3/include/php” folder. the “include/php” folders i would have to create then, right?

    • I have the previous version of MAMP. I am not sure how much has changed, but the target directory is /Applications/MAMP/bin/php5/include/php/ not /Applications/MAMP/bin/php5.2(3 in your case)/include/php/

  4. mori says:

    mori-mbp-17:~ mori$ CFLAGS=”-arch i386″ ./pecl install
    -bash: ./pecl: No such file or directory

    Guess I got something essential wrong. But what?

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.