Installing Memcache on CentOS 7 running PHP 5.6

What is Memcache? It is a free & open source, high-performance, distributed memory object caching system.

Let's get started

First install nc:

sudo yum update && install nc

Next, we need to install Pecl memcache beta version because this is version 3.0.8 (which is required by the Drupal module). Otherwise, it we install the stable version and we will get version 2.2.7 instead.

pecl install memcache-beta

yum install memcached

Wait for it to complete compiling. You don’t need to add to php.ini file, it should do this for you.

Now, we need to configure it, enter:

sudo nano /etc/sysconfig/memcached

Update it as follow:

# max connection 2048
# set ram size to 2048 - 2GiB
# listen to loopback ip, for network connection use real ip e.g.,

The above will starts memcached up as a daemon, using 4GB of memory, and listening on IP, port 11211. Save and close the file.

Type the following command to start memcached, enter:

chkconfig memcached on
service memcached start

To stop / restart use the following commands:

service memcached stop
service memcached restart

To view the memcached stat, type the following command:

memcached-tool stats

If fail to connect to 11211, check this:

Finally, restart Apache:

sudo systemctl restart httpd.service

Once it is working, we can begin to use this with Drupal to improve caching.

Let's now setup the Drupal module to use Memcached.

- Install and enable the module:
- Open up /sites/default/settings.php and add the following to the bottom of your file:

For Drupal 7:

$conf['cache_backends'][] = 'sites/all/modules/memcache/';
$conf['lock_inc'] = 'sites/all/modules/memcache/';
$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'] = 'mydomain_com';

For 'memcache_key_prefix', give it a unique value, such as mydomain_com

For Drupal 8:

$settings['memcache']['servers'] = ['' => 'default'];
$settings['memcache']['bins'] = ['default' => 'default'];
$settings['memcache']['key_prefix'] = 'mydomain_com';

For memcache_key_prefix, give it a unique value, such as mydomain_com

These are just standard values that should be sufficient but if you have more specific needs for a different configured server, check the module's README.txt file


Thanks to this article:

If you are looking for installing memcache on  EA4 for PHP 7, follow this link

The content of this field is kept private and will not be shown publicly.
Your email address will be kept private and will not be shown publicly.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.