HOWTO: Use Advanced Drupal Caching From Your Desktop

I (heart) the DAMP/Acquia Stack Installer. It makes rapid testing and development easy, and helps me be productive on airplanes even without wifi. In this post I'll explain how I was able to quickly set up an advanced caching testbed on my desktop to investigate some advanced APC and memcache configurations.

Caveat: these instructions are all MacOS centric — apologies in advance to the Redmond-faithful, happy to finally be caught up with all the Ubuntu-ites — but that's my environment and over the years I've found it to be a good one.

First two easy point-and-clicks.

  1. Download and run the DAMP installer.
  2. Next, since I roll with Pressflow and what I wanted to test was a potential new branch, I grabbed myself a copy of BZR, another cool next-generation version control system with an installer.

Now's where the work starts. I pop open my handy iterm and quickly grab a fresh branch of Pressflow:


mithras-4:pressflow joshk$ cd
mithras-4:~ joshk$ cd Sites/
mithras-4:Sites joshk$ bzr branch lp:pressflow
Branched 78 revision(s).


Then fire up your Acquia Stack, pick "More..." from the little sites drop-down, click the import button, and find the freshly branched codebase. Note: this is a great way to set up/run any codebase locally, not just a Pressflow branch. If you've got an existing site tarball, your own SVN repository, or want try out a cool Drupal product like Open Atrium, you can use DAMP to easily import the pre-existing Drupal.

Next thing I do is install Drush. Drush: don't leave home without it. Now, there's an important tweak you'll want to use to get Drush and the DAMP installer working in harmony: adding the acquia-stack php path to the drush helper script. Hopefully that issue will be committed soon, but in the mean time it's a very small fix: just add /Applications/acquia-drupal/php/bin/php to the bit where Drush searches for *AMP installations.

Once I had drush set up, I ran drush dl devel memcache-6.x-1.x-dev to grab the latest Devel and Memcache modules, since my eventual aim was to do some performance.module based testing.

And now we come to the fun part. See, while DAMP ships with a lot of commonly-needed libraries like GD and curl, it doesn't come with the php components to support APC or memcached, both of which I need for my tests. Thankfully JAM has my back, and we got support for custom php libraries baked into the latest releases of the DAMP installer. Those copy/paste instructions worked like a charm to install APC, so that was out of the way and it was on to memcached.

Memcached isn't just a PHP module, it's also the caching system itself, so we need to install that too. This is old hat to any linux/BSD-head who's built from source before, but for the uninitiated here's the voodoo.

First set up a nice working directory and navigate to that directory in your terminal. If you're reading this later than April 2010, you may want to see if there are more current releases of libevent and memcached and update the wget commands appropriately, but:


tar -xzvf libevent-1.4.13-stable.tar.gz
cd libevent-1.4.13-stable
sudo make install


Same for the memcache daemon itself:


tar -xzvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
sudo make install


Then repeat Acquia's custom php library instructions for memcache.

Finally, start up a quick memcache bin like so:


/usr/local/bin/memcached -m 32 -d


At that point I'm ready to add the memcache settings to my local sites settings.php file and I'm off to the races.

Three cheers to Acquia, the Drush team, and to the makers of MacOS, Libevent and Memcached for (finally!) getting us to the point where building open-source projects is as simple as configure, make, install.