April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

How to setup Memcache on CentOS 7 for Drupal site

How to setup Memcache on CentOS 7 for Drupal site

One way to optimize the authenticated users experience in Drupal site is to use Memcache. It works between the database and Drupal.
Typically the queries are cached in the database but with Memcache the queries sent from Drupal to database are intercepted by Memcache and it serves them from RAM and this avoid hits to the disk or database. We see often that half of the queries are served by Memcache and we are looking significant improvement in authenticated users hits.

Lets take a look how to setup Memcache on CentOS 7 for Drupal site.

Install the Memcache daemon:
yum -y install memcached

Configure Memcache daemon:
vi /etc/sysconfig/memcached

Change the following:

CACHESIZE=”256″
OPTIONS=”-l 127.0.0.1″

CACHESIZE is the RAM you allot to Memcache daemon. Start it:

systemctl start memcached.service
systemctl enable memcached.service

Confirm the Memcache service running status:

memcached-tool 127.0.0.1:11211 stats

Check the remote connectivity:

watch “echo stats | nc 127.0.0.1 11211”

To integrate PHP and Memcache we need to install php-pecl-memcache:

yum -y install php-pecl-memcache

In your Drupal site’s “settings.php” file, append the following codes:

/**
* Memcache configurations
*/
$conf[‘cache_backends’][] = ‘sites/all/modules/memcache/memcache.inc’;
$conf[‘lock_inc’] = ‘sites/all/modules/memcache/memcache-lock.inc’;
$conf[‘memcache_stampede_protection’] = TRUE;
$conf[‘cache_default_class’] = ‘MemCacheDrupal’;
// The ‘cache_form’ bin must be assigned to non-volatile storage.
$conf[‘cache_class_cache_form’] = ‘DrupalDatabaseCache’;
// Don’t bootstrap the database when serving pages from the cache.
$conf[‘page_cache_without_database’] = TRUE;
$conf[‘page_cache_invoke_hooks’] = FALSE;
// If this server has multiple Drupal installation
// assign unique key for memcache namespace purposes
$conf[‘memcache_key_prefix’] = ‘www_yoursite_com’;

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>