Install Memcache for Drupal Tutorial

Memcache stores a copy of data. So Server can use it next time later without going through the entire process it passed first time to get it. It includes files, database etc. Which boosts the performance of your site or application and reduces the load on your server.

In the below article we will learn how to install memcached in Linux Mac to improve performance for Drupal

Step 1 : Update Apt-get or Yum Command
sudo apt-get update      (Ubuntu)
OR
sudo yum update         (Centos , Redhat)
Step 2 :
sudo apt-get install memcached libmemcached-tools           (Ubuntu)
OR
yum install memcached            (Centos , Redhat)
Step 3 :
sudo apt-get install php5-dev php-pear make                  (Ubuntu)
OR
sudo yum install php5-dev php-pear make                  (Redhat, Centos)
Step 4 :
sudo pecl install memcache                   (Ubuntu, Redhat, Centos)
Step 5 : Include the below Lines
sudo vi /etc/php.d/memcache.ini                         (Centos , Redhat)
OR
sudo vi /etc/php5/conf.d/memcache.ini                   (Ubuntu)
(Note : If no file exist you can Run $locate memcached)
extension=memcache.so
memcache.hash_strategy=consistent

(Note : If line are all-ready present but comment you can un-comment it.)


Step 6 : Check if you have following Lines if not then add them
vi /etc/sysconfig/memcached (Centos , Redhat)
(Note : If no file exist you can Run $locate memcached)

And Verify below settings

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""
Step 7 : Start your Memcached Server now
sudo service memcached start
OR:
sudo /etc/init.d/memcached start
Step 8 : Download Drupal Memcache Module from the below URI and enable it.
https://drupal.org/project/memcache

Step 9 : Include the below line for in sites/default/settings.php
$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';   ( Drupal 7 )
$conf['cache_default_class'] = 'MemCacheDrupal';            ( Drupal 7 )
$conf['memcache_key_prefix'] = 'something_unique';   ( Drupal 7 )( Optional if 
there are more Sites in your Server )
OR
$conf['cache_inc'] ='sites/all/modules/memcache/memcache.inc';                 ( Drupal 6 )

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now