Setting up memcached with Drupal 7 on Centos 6

Firstly get access to RPMForge repositories. Next install memcached:

sudo yum install memcached
sudo service memcached start
memcached -h

Check memcache stats:

echo "stats settings" | nc localhost 11211
watch "echo stats | nc 127.0.0.1 11211"

Configure memcache:

sudo vi /etc/sysconfig/memcached

Configuration details for memcache can be found here

Install the PECL memcached extension for PHP

sudo pecl install memcache
echo "extension=memcache.so" | sudo tee -a /etc/php.ini
sudo service httpd graceful
php -i | grep memcache

Install the memcache drupal module and configure the website via settings.php

https://drupal.org/project/memcache

drush dl memcache

You don’t need to enable the module unless you want a stats UI.

Edit your site’s settings.php, adding something like the following:

$conf['cache_backends'][] = 'sites/all/modules/contrib/memcache/memcache.inc';
// The 'cache_form' bin must be assigned no non-volatile storage.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['memcache_key_prefix'] = 'something_unique';

Truncate the cache table, clear the cache and check that the cache table stays empty when you load some pages. Check the memcache stats and see that data is going into the cache.

Hopefully it’s working now!

References

Drupal Memcache module – https://drupal.org/node/1131468

Configuring Memcache from the memcache wiki – https://code.google.com/p/memcached/wiki/NewConfiguringServer

 

By Sam

Drupal developer from Perth, Western Australia. I love programming, gaming, the Internet, growing vegetables and hiking.

2 comments

  1. Thank you for the great post! This is much better than the existing docs and actually worked. I am running CentOS 6.5 on Drupal 7 and got a WSOD using your settings.php changes though.

Leave a Reply to Richard Cancel reply

Your email address will not be published. Required fields are marked *