Compiling a PHP Memcache extension with MAMP 1.9.5

By Joel Stein on April 12, 2011

Any Drupal developer needing Memcached for local development has probably read Lullabot’s famous Setup a Memcached-Enabled MAMP Sandbox Environment. It’s a great primer, but if you are using a more recent version of MAMP, you may need newer instructions.

Here are the steps I took to get a memcache.so extension file for the two versions of PHP bundled with MAMP 1.9.5. Provided that you have Apple’s Xcode and PECL installed, you should be able to paste the following commands into Terminal. Or you can just download the PHP 5.3.5 file directly:

PHP 5.3.5

pecl download memcache
tar xvfz memcache-2.2.6.tgz && cd memcache-2.2.6
ln -s /Developer/SDKs/MacOSX10.6.sdk/usr/include/ /Applications/MAMP/bin/php5.3/include
/Applications/MAMP/bin/php5.3/bin/phpize
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.3/bin/php-config
make
cp modules/memcache.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/
rm /Applications/MAMP/bin/php5.3/include

PHP 5.2.17

pecl download memcache
tar xvfz memcache-2.2.6.tgz && cd memcache-2.2.6
ln -s /Developer/SDKs/MacOSX10.5.sdk/usr/include/ /Applications/MAMP/bin/php5.2/include
/Applications/MAMP/bin/php5.2/bin/phpize
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.2/bin/php-config
make
cp modules/memcache.so /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/
rm /Applications/MAMP/bin/php5.2/include