Ubuntu 14.04, libmemcached and SASL support

UPDATE (Jan, 2016): As of Ubuntu 15.10, libmemcached is built with SASL support. We suggest all users migrate to an up to date version of Ubuntu.

Any Ubuntu 14.04 LTS users may have noticed that the provided libmemcached package doesn’t support SASL authentication. This is a major issue as it means that any memcache client that depends on libmemcached (which is a lot!) doesn’t work with MemCachier or similar services out-of-the-box as they can’t authenticate with our servers.

We are trying to do two things to address this:

  1. Asking Ubuntu to build with SASL support (bug report)
  2. Submitting a patch to libmemcached to remove the libsasl2 dependency and implement SASL directly so that it is always build with SASL support (patch)

UPDATE (Jan, 2016): We haven’t made any progress on (2) sadly as the libmemcached maintainer is very unresponsive.

Until either of those two work out though, Ubuntu users will need to compile libmemcached themselves to get SASL support. Luckily this is very easy and we’ll show you how.

First, remove the existing libmemcached install if present:

$ sudo apt-get remove libmemcached-dev
$ sudo apt-get autoremove

Now, make sure libsasl2 is installed and the build tools you’ll need:

$ sudo apt-get install libsasl2-dev build-essential

Then, grab the latest source code for libmemcached and build it:

$ wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
$ tar xzf libmemcached-1.0.18.tar.gz
$ cd libmemcached
$ ./configure --enable-sasl
$ make
$ sudo make install

This will just install in /usr/local, if you want you could install to /opt or similar instead but then you’ll need to tell any software that depends on libmemcached about this custom location, so we recommend just sticking with the default location.

You can now test this by compiling and trying to run the following C code:

Save it to a file (say sasl_test.c) and compile it as follows:

$ gcc -o sasl_test -O2 sasl_test.c -lmemcached -pthread

Then test that it works by simply creating a free development cache at MemCachier and using the provided username, password and server:

$ ./sasl_test user-233 password-233 mc5.dev.ec2.memcachier.com

It should work if libmemcached is setup correctly, and if not, it’ll print out where it went wrong.