How to implement Memcached in Drupal 7?

This tutorial can NOT be combined with an implementation of Redis in Drupal 7

To implement Memcached as easily as possible in Drupal 7, proceed as follows:

  1. First make sure you Activate Memcached caching from your control panel. You will need the IP and port number form there.
  2. Check the PHP version. The module counts on specific PHP extensions. PHP 5.6 or earlier would work. PHP 7 will not work with this tutorial.
  3. Login in the backend. This can be done by generating a single sign-on link via drush.
    drush uli -l ninefortwo.be
    

    You type this in the root directory of the Drupal installation. Here you get a link that looks approximately like this:

    https://ninefortwo.be/user/reset/1/1456307446/R022fU2OH1QEopq7PsxBXKzgk92Op0kfV_yKIXeY1EU/login
    

    Please note that this link is valid only once. If you logged out, you will have to generate a new link.

  4. Install the “Memcached” module
    1. Once logged in, go to “Modules” => “Install new module”.
    2. Go to https://www.drupal.org/project/memcache and please copy the link to the zip file of the latest release of Drupal 7.
    3. Then paste this URL into the text field “Install from a URL” and click “Install”
  5. Activate the module
    1. Click “Modules” in the backend of Drupal. Now search for “memcache” in the list of modules.
    2. Switch on both the module “Memcache” and the module “Memcache_Admin” and click “Save settings” (button on the left bottom)

    Note: The “Memcache Admin” module provides the option to display Memcache stats on each page. However, this is not required for the operation of Memcache. It is convenient and we use it later for test purposes.

  6. Adjusting the configuration of the Memcache module
    1. In ssh, change to the sites/default/ directory.
    2. Add the following to the bottom of the file settings.php:
      /* Memcache config
      * Please leave the settings below untouched
      */
      $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
      $conf['cache_default_class'] = 'MemCacheDrupal';
      $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
      $conf['page_cache_without_database'] = TRUE;
      $conf['page_cache_invoke_hooks'] = FALSE;
      $conf['memcache_servers'] = array(
      '250.250.250.1:10000' => 'default',
      );
      $conf['memcache_bins'] = array(
      'cache'           => 'default',
      );
      
    3. Replace 250.250.250.1:10000 with your IP address and port
  7. Test. Now go to the Drupal backend to “Settings” => “System” => “Memcache”. Here, check the option to display statistics Memcache and then browse to the site. If you have correctly configured Memcached, at the bottom of the page a table of statistics of the memcached usage will show up. After you have used the stats for a test, feel free to switch them off.
Updated on 24 September 2020

Was this article helpful?

Need Support?
Can't find the answer you're looking for?
Contact Support

Couldn't find a solution?

support_bottom_contact_alt

Our specialists are available 24/7 to provide you with free support. Feel free to contact Joachim and his colleagues via e-mail or by phone.

support_bottom_contact_alt
Joachim Coessens Specialist Support