Configuring Drupal to use Redis
To help improve your site's performance, you can configure Drupal to use Redis, and this article shows you how. Please note that you must have a VPS or Dedicated Server to use Redis.
This article describes how to configure Drupal 9 to use Redis.
Redis is an open-source memory object caching system that websites can use to help accelerate page load times. Redis works by caching in RAM frequently accessed data, such as the results of API calls, database calls, and more.
Note
Redis is currently enabled on Turbo shared, Turbo reseller, Managed VPS, and Managed Dedicated server accounts.
If you have an unmanaged VPS, you have full root access and can install and configure Redis yourself.
Redis is not supported on non-Turbo shared hosting accounts at this time.
Installing the dependencies and module
First, you must install some dependencies and a module so Drupal can access and use Redis. To do this, follow these steps:
-
Log in to your account using SSH.
-
At the command prompt, change to the directory where you installed Drupal.
-
Type the following commands:
composer require predis/predis
composer require drupal/redis
cp modules/contrib/redis/example.services.yml sites/default/redis.services.yml
-
Log in to your Drupal site as the administrator.
-
On the top menu bar, click Extend.
-
On the List tab, under PERFORMANCE, select the check box next to Redis.
-
Click Install. You receive a Module Redis has been enabled message.
Configuring Drupal settings
After you install and enable the Redis module, you are ready to configure Drupal to actually use Redis. To do this, follow these steps:
-
In the directory where you installed Drupal, use your preferred text editor to open the sites/default/settings.php file.
-
Configure the Redis connection settings:
- If you have a Managed VPS or Dedicated Server, copy the following text and append it to the settings.php file:
$settings['redis.connection']['interface'] = 'Predis';
$settings['redis.connection']['host'] = 'localhost';
$settings['redis.connection']['port'] = '6379';
$settings['cache']['default'] = 'cache.backend.redis';
$settings['container_yamls'][] = 'sites/default/redis.services.yml';
- If you have a Turbo shared or reseller account, copy the following text and append it to the settings.php file. Replace username with your account username:
$settings['redis.connection']['interface'] = 'Predis';
$settings['redis.connection']['host'] = '/home/username/.redis/redis.sock';
$settings['redis.connection']['port'] = NULL;
$settings['cache']['default'] = 'cache.backend.redis';
$settings['container_yamls'][] = 'sites/default/redis.services.yml';
Tip
For additional information about these options, see the modules/contrib/redis/README.md file.
- Save your changes to the settings.php file. Redis is now configured for Drupal.
Tip
To verify that Drupal is working correctly with Redis, on the top menu bar of the administration interface, click
Reports , and then click
Redis . You should see a
Connected, using the Predis client message, along with statistics about the Redis cache and connection. If you see a
Not connected message, then Redis is not integrated with Drupal.
More Information
For more information about Redis, please visit https://redis.io.
Related Articles
Updated 1 day ago