Saturday, November 12, 2022

[FIXED] How to implement Memcache in Drupal 8?

Issue

I read a few very good online resources that describe how exactly we can implement Memcache in Drupal 8. for e.g. this one

https://www.valuebound.com/resources/blog/configuring-memcache-drupal-8-to-reduce-database-load

At the Drupal end I have installed two new modules for Memcache:

  1. Memcached
  2. Memcached Storage

But, when trying to enable them it throws an error "PHP extension is required".

Also, getting this error "Unable to initialize module" when trying to install PHP extension using below command:

sudo apt install php-memcached


Solution

Finally, I found the solution.

Add Memcache in Drupal-8

  1. Added two new modules and installed them in Drupal.

    • Memcache
    • Memcache Admin

  1. Install below packages in existing Drupal Dockerfile.

    • libmemcached-dev
    • memcached
    • Docker-php-ext-enable memcached
  2. Finally, update settings.php with memcache configs (../web/sites/default/settings.php)

$settings['memcache']['servers'] = ['127.0.0.1:11211' => 'default'];
$settings['cache']['bins']['render'] = 'cache.backend.memcache';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.memcache';
$settings['memcache_storage']['debug'] = TRUE;

Note: We can view Memcache statistic via https://localhost/admin/reports/memcache

enter image description here

Memcache is installed successfully!



Answered By - Aftab
Answer Checked By - David Marino (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.