Last updated November 25, 2015. Created on September 27, 2013.
Edited by Spleshka. Log in to edit this page.

To set up a basic memcached integration with Drupal you need to pass next three steps:

Install memcached daemon

First you need to do is to run a memcached daemon on your server. The installation is pretty simple, because generally you need only installation from package.

If you need an extended version of memcached daemon (for example, sasl auth support), please refer the documentation for installation from source or lullabot's guide.

Install PECL extension

After installation of memcached daemon you need to add a library, that provides integration between php and memcached daemon. You can choose one of two pecl extensions: PECL Memcache or PECL Memcached. You don't need to install them both, but if you did this, nothing bad will happen.

Install PECL Memcache extension

Installation of this package shouldn't cause any issues, because in generally all you need is to run single command for installation from repository. You are free to search info using you favourite search engine and query "Install pecl memcache on @OS", where @OS is a real name of your OS. There are a lot of documentation for this, so I don't see a reason to provide a special links. While reading articles do not forget that you might already install memcached daemon (because a lot of articles includes this information too).

Please note, that PECL Memcache's version should be 2.2.1 or greater.

Install PECL Memcached extension

Most OS's contains old version of PECL Memcached, so you will probably have to compile this extension yourself. You need at least 2.0.1 version or greater. In generally process of compillation looks like this:

git clone;
cd php-memcached && phpize
./configure && make && make install

Please note, that PECL Memcached extension requires libmemcached library. Installation of libmemcached in general looks like this:

tar xvfz libmemcached*.tar.gz
cd libmemcached*
./configure && make && make install
cd ../ && rm -rf libmemcached-*

But sometimes it is also fine to install libmemcached-dev package from repository (depends on your OS).

Installation of PECL Memcached is not so easy, as PECL Memcache, but it worth it, because it provides more features and better performance.

Install Memcache Storage

1. Download and extract Memcache Storage module into sites/all/modules (or appropriate) directory.

2. Install the Memcache Storage module as usual.

3. Put your site into offline mode.

4. Edit settings.php to configure Memcache Storage module. Basic configuration looks like this:

Drupal 7:

  $conf['cache_backends'][] = 'sites/all/modules/memcache_storage/';
  $conf['cache_default_class'] = 'MemcacheStorage';
  $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
  $conf['cache_class_cache_update'] = 'DrupalDatabaseCache';

Drupal 8:

$settings['cache']['default'] = 'cache.backend.memcache_storage';

5. Go to Status report page (/admin/reports/status) to check Memcache Storage status.

6. Bring your site back online.

After following steps all your cache (except {cache_form} and {cache_update} tables) should be moved to the memory.

Looking for support? Visit the forums, or join #drupal-support in IRC.


cristiroma’s picture

When I use the instructions above, I get the following fatal error:

PHP Fatal error: Class 'MemCacheDrupal' not found in /var/local/cms/www/includes/ on line 31

In order to fix that, I had to add this line:

require_once './sites/all/modules/memcache_storage/';
Spleshka’s picture

MemCacheDrupal class comes with Memcache module, not with Memcache Storage. The step 4 is 100% correct.

Neograph734’s picture

There is a known issue #1954348: Fields not available anymore in fields add (cache issue) causing Views UI to behave strangely when using memcached. In some cases it could help to add
$conf['cache_class_cache_views'] = 'DrupalDatabaseCache'; to settings.php.

Since the issue states this is backend related, this module might have problems with it too.