Compiling a PHP Memcache extension with MAMP 1.9.5

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 Tools and PECL installed, you should be able to paste the following commands into Terminal. Or you can just download the files directly:

  • /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/memcache.so
  • /Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/memcache.so

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

 

Comments

Hey this works great, I spent a considerable amount of time on the lullabot tutorial, but still had issues. This saved our developers a considerable amount of time.
Great blog, keep it up!

There are so many other tutorials about this online that lead me nowhere. Thanks so much for making it this easy!

Thank you so much! Great works, Great blog.

Thanks so much for the direct downloads of the .so files. I couldn't get it to compile. Thanks again

Wow, finally a tutorial that works really great!

I tried 10s of others and always got an error with that one. Success at first try. Did work fine for getting xhprof to work as well!

Great job!

Great! This also works with MAMP 2 with PHP 5.2.17 and PHP 5.3.6.

Thank you very much for the compiled versions!

Add new comment