- Make sure phpinfo(); (available at /admin/reports/status/php in Drupal for administrators) contains a memcached section – by default Lando will install the memcached PECL package.
- Install and enable memcache Drupal module.
- configure settings.php:
$settings['memcache']['servers'] = ['cache:11211' => 'default']; $settings['memcache']['bins'] = ['default' => 'default']; $settings['memcache']['key_prefix'] = 'mysitename_'; $settings['cache']['default'] = 'cache.backend.memcache';
Note the hostname for external connections (port 11222) is localhost, but internal connections have a different hostname: cache – to verify, run
(give it the correct sitename – this is especially important if you ever use memcached for two or more sites on the same server, to avoid conflicts.
Also, note memcached has no security so if an application knows or can guess another applications’ prefix it can read all the data.
- Truncate all MySQL tables beginning with
cache(Drupal bootstraps from the database by default and otherwise may continue to use them)
- Run drush cr
- You can should now work.
Verify connection and performance (e.g. hits/misses and memory used) at /admin/reports/memcache
Way to test an internal connection from PHP in a container, if you can’t install what you need:
php -a > $socket = fsockopen('cache', "11211", $errno, $errstr);
If you don’t see any errors, it has connected.