[Drupal] How to install and configure Memcached on a Drupal 6 site?

| | 2 min read

Drupal uses a variety of caching systems to improve the site performance. However in certain scenarios they may not be sufficient and more powerful external caching mechanisms are required to improve the performance. One such mechanism is memcached. If you want to know how to install memcached in CentOs then read on to know the steps.

We had encountered such a scenario in one of our Drupal sites where the inbuilt caching mechanisms were not sufficient and Memcached turned out to be the savior. Memcached is a distributed caching system operating in memory and helps to reduce the database load and make the site faster. Each memcached daemon is able to store data as an object (key value pairs). However, simply installing memcached on your server will not make your site run any faster. To do that you have to make use of its API.

Installing Memcache


  • OS - CentOS.
  • PHP5 or higher version

Steps to install memcached on CentOS

Install memcached using

yum install memcached

Then start memcached using the command

service memcached start

Memcached listens on port 11211. Check this using the command

netstat -tap | grep memcached

Then install memcache php extension using the command

pecl install memcache

Now restart Apache using

service httpd restart

After completing these steps without any errors, you are good to go. Drupal has an API integration with memcached.

Installing Memcache module in Drupal 6

Download the memecache module and extract it into sits/all/modules and enable it.
Now you need to add two lines of code into your site's settings.php file.

$conf['cache_inc'] ='sites/all/modules/memcache/memcache.inc';
$conf['memcache_key_prefix'] ='the-name-of-the-site';

You may face a few problems while enabling memcache. Memcache needs php ini_set function enabled. If it is not, enabling the module will result in a lot of errors. In some servers ini_set is disabled because of some security reasons. You can enable it in your server by removing ini_set from disable_functions in php.ini file. Finally remember to restart Apache.

Hope this article was helpful. Share it and post your feedback as comments.