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:

1
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. Running the .dmg should extract the source. After extracting the source run the following:

1
2
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:

1
2
3
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:

1
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!