Posted on 2012-06-03 20:05:50+00:00
Setting up Drupal 6 to use memcached is anything but trivial. There are plenty of instructions out there, but many of these are for MAMP 1.x, or involve MacPorts. This post will show you how to quickly set up memcached locally. Best of all, this guide will leave your system ready to install other PECL extensions quickly.
You will need XCode and MAMP 2.0 installed for any of this to work. Also, it assumes you're using PHP 5.2 through MAMP's settings, but it probably works with 5.3 too. Onward.
First and foremost, you should set up Homebrew. It's dramatically better than MacPorts. To install it - if you haven't already done so - just run:
Once that's done, we're ready to install memcached and libevent. Do that with:
1 2 3 4 5
And that's it for the easy part. Kudos to homebrew for making this very straightforward. Now for the interesting part.
To install a PECL extension using MAMP, you need to grab the PHP source. Go ahead and do this now by going to http://us.php.net/distributions/php-5.2.17.tar.bz2, changing
5.2.17 to whatever version of PHP 5.2 your MAMP installation has. To find this out, run
find /Applications/MAMP/bin/php -name 'php5.2*' and make note of the last directory.
Once you've got the source, you'll need to extract it in
/Applications/MAMP/bin/php/php5.2.17 under a folder structure with the path
include/php. Confusing? These lines will do it for you.
1 2 3 4 5
Now we've need to run
./configure on the PHP source, and remove
pear.conf from the MAMP distribution - it comes corrupted out of the box, for some reason.
1 2 3 4
And finally, we're ready to install the memcached PECL extension and add it to php.ini so it's enabled. Like so:
1 2 3 4 5
And that's it. This leaves you at the root of MAMP's installation. You should restart MAMP and enjoy fast caching. Don't forget to start memcached by running:
This will start an instance that prints activity to the screen. Very useful when debugging locally, and very easy to restart. This completes the tutorial.
If you ever need to install another PECL extension, your MAMP installation now has all the necessary tools to do so. Just use the PECL binary in
/Applications/MAMP/bin/php/php5.2.17/bin and you should be good to go.
Below is the entire set of commands, for posterity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
homebrew repo is in slightly different location (here's the command listed on the homebrew page): ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Otherwise, this worked perfect. Thanks!
Installing Memcache on MAMP
Step 1: Install XCode Step 2: Make the MAMP PHP binary files executable Step 3: Get the Memcache extension source Step 4: PHPize the Memcache extension files Step 5: Compile the Memcache extension Step 6: Add the extension to the PHP.ini file Step 7: Copy the memcache extension to the PHP extension folder