Configuring Drupal to use memcached
Memcached is a high‑performance, distributed memory caching system that stores frequently accessed data in RAM. Configuring Drupal to use Memcached can significantly improve site performance by reducing database queries. On ruachost.com, Memcached is available on Managed VPS accounts. Contact Ruachost support to check availability on your shared hosting plan.
Why Use Memcached with Drupal?
Section titled “Why Use Memcached with Drupal?”- Faster page load times by caching queries in memory.
- Reduced database load.
- Improved scalability for high‑traffic sites.
- Enhanced performance for APIs and dynamic content.
Steps to Configure Drupal to Use Memcached
Section titled “Steps to Configure Drupal to Use Memcached”Step 1: Install Dependencies and Module
Section titled “Step 1: Install Dependencies and Module”-
Log in to your server via SSH.
-
Navigate to your Drupal installation directory.
-
Run the following commands:
Terminal window composer require drupal/memcache -
Copy the example Memcached services file:
Terminal window cp modules/contrib/memcache/example.services.yml sites/default/memcache.services.yml -
Log in to Drupal as an administrator.
-
Go to Extend → List tab → Performance.
-
Check the box next to Memcache and click Install.
-
You should see a confirmation message: Module Memcache has been enabled.
Step 2: Configure Drupal Settings
Section titled “Step 2: Configure Drupal Settings”-
Open the
sites/default/settings.phpfile in a text editor. -
Add the following configuration based on your hosting type:
For Shared Hosting Accounts (where available)
Section titled “For Shared Hosting Accounts (where available)”$settings['memcache']['servers'] = ['/home/username/.memcache/memcached.sock' => 'default'];$settings['memcache']['bins'] = ['default' => 'default'];$settings['cache']['default'] = 'cache.backend.memcache';$settings['container_yamls'][] = 'sites/default/memcache.services.yml';(Replace
usernamewith your account username.) -
Save the file.
Step 3: Verify Memcached Integration
Section titled “Step 3: Verify Memcached Integration”- In the Drupal admin menu, go to Reports → Memcache.
- Look for the message: Connected, using the Memcache backend.
- Review Memcached cache statistics to confirm proper integration.
Important Notes
Section titled “Important Notes”- Memcached is not available on every shared hosting plan. Contact Ruachost support to confirm availability for your account.
- Always back up your site before making configuration changes.
- For advanced options, see the
modules/contrib/memcache/README.mdfile.