Install Memcache for Drupal on CentOS 5.5

Submitted by Janak on Mon, 09/27/2010 - 17:21

Install EPEL Repo

Memcache can be found in the EPEL repo. Install EPEL repo:

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Install Memcache

yum install memcached
pecl install memcache
yum install zlib-devel

Auto start memcache on reboot

chkconfig --level 2345 memcached on

Add PHP settings for Memcache

nano /etc/php.d/memcache.ini

extension=memcache.so
memcache.hash_strategy="consistent"

Start Memcache and Apache

/etc/ini.d/httpd restart
/etc/init.d/memcached start

Memcache Check

Check if memcache module is loaded in php

php -i | grep memcache

You should see an output similar to this:

/etc/php.d/memcache.ini,
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user memcache

done ;)

Memcache Drupal settings

  • Download and install the Drupal memcache module
  • Update your settings.php file

    $conf = array(
       // The path to wherever memcache.inc is. The easiest is to simply point it
       // to the copy in your module's directory.
       'cache_inc' => './sites/all/modules/memcache/memcache.inc',
       // or
       // 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc',
    );
     
     
    $conf = array(
      'memcache_servers' => array('localhost:11211' => 'default',
                                  'localhost:11212' => 'pages'),
      'memcache_bins' => array('cache_page' => 'pages'),
    );

Further reading:

Memcache API and Integration
Installing Memcached on RedHat or CentOS