How to Host Drupal 8 Websites with Redis on VPS Plans

Introduction: Redis as Backend NoSQL Cache for Drupal 8

This Tutorial will show how to install Redis as a backend cache on a VPS hosting plan for a Drupal 8 website with an overview of the modules needed for platform integration.

Redis is a NoSQL database that can be used as a backend cache on a LAMP web server running Drupal 8 to drastically reduce the number of MySQL database queries.

Redis can be combined with PHP caching (Memcached, Zend Opcache, APC), HTML/CSS & JavaScript caching (Adv Agg), reverse-proxy caching (NGINX), & Varnish Cache to run Drupal 8 at high performance levels for demanding apps.

Step One:
Install Redis on the Web Server

HostAdvice has published a number of excellent Tutorials with step-by-step instructions for installing Redis on a Linux web server:

With CLI tools & LAMP servers, the following commands can be used to install Redis:

Using Yum:

yum install redis

Using Apt-Get:

apt-get install redis-server

Using Sudo:

sudo apt-get install redis-server

In CentOS, the Redis extension can be selected as part of the “Select PHP Version” section of the administration:

How to Host Drupal 8 Websites with Redis on VPS Plans

Install Redis on the web server according to the Linux version in use and then proceed to the next step to add the integration module for Drupal 8.

Step Two:
Install the PHP Redis Client (PhpRedis)

Before the Drupal 8 integration module is installed, make sure that the PECL module for the PHP Redis Client is present on the web server & enabled. Run the command:

pecl install redis

The PHP Redis Client enables the software to store PHP session variables on a web server in addition to MySQL database queries, adding an extra caching layer.

Use the following code to install PHP Redis using Apt-Get & Git:

apt-get install php7.0-dev git
git clone
cd phpredis
git checkout php7
make && make install
cd ..
rm -rf phpredis
echo "" > /etc/php/7.0/mods-available/redis.ini
ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/fpm/conf.d/20-redis.ini
ln -sf /etc/php/7.0/mods-available/redis.ini /etc/php/7.0/cli/conf.d/20-redis.ini
service php7.0-fpm restart

Note: PHP Redis is from an open source development team independent from the Redis NoSQL development project, but this functionality is required by the D8 module.

Step Three:
Install the Redis Module for Drupal 8

Next download the Redis module for Drupal 8 and install at: /admin/modules/install or use Drush, Composer, FTP, etc. to install/enable the module according to preference.


The Redis module for Drupal 8 has no formal administration screen but provides the bridge for integration with the PHP Redis framework for PHP session variable caching.

How to Host Drupal 8 Websites with Redis on VPS Plans

Install & enable the Redis module in Drupal 8 admin or use the Drush command:

drush en redis

How to Host Drupal 8 Websites with Redis on VPS Plans

Consider the use of modules like Purge for management of the Redis cache settings through the Performance section of Drupal 8 administration.

Note: The back-end caching of PHP & MySQL server functions provided by Redis operates in the data center at a layer beneath HTML, CSS, & JavaScript compression.

Step Four:
Configure Drupal 8 for PHP Redis Integration

In order for the Drupal 8 integration for PHP Redis to work successfully, administrators will need to add the following lines to the settings.php file in /sites/default folder:

$settings['redis.connection']['host'] = 'localhost';
$settings['redis.connection']['port'] = NULL;
$settings['cache']['default'] = 'cache.backend.redis';
$settings['redis.connection']['base'] = 101;

The Redis Connection Base Variable can be any number and should be used to keep different Drupal 8 installations separate from other websites or domains running Redis on the same web server. A custom IP Address can be used in place of “localhost”.

For more advanced configuration of Redis NoSQL variable functions, use the code:

$settings['redis.connection']['interface'] = 'PhpRedis';                  // Can be "Predis" in the future
$settings['redis.connection']['host']      = '';                 // Your Redis instance hostname
$settings['cache_prefix']                  = 'example-text';         // Optional prefix for cache entries

$settings['cache']['default']              = 'cache.backend.redis';       // The default cache engine for the site
// Always set the fast backend for bootstrap, discover and config, otherwise this gets lost when redis is enabled.
$settings['cache']['bins']['bootstrap']    = 'cache.backend.chainedfast';
$settings['cache']['bins']['discovery']    = 'cache.backend.chainedfast';
$settings['cache']['bins']['config']       = 'cache.backend.chainedfast';

$settings['container_yamls'][] = 'modules/redis/';
$settings['container_yamls'][] = 'modules/redis/';

//Register our namespace
$class_loader->addPsr4('Drupal\redis\', 'modules/redis/src');

Set the Cache Prefix values with any label taxonomy and leave the other settings as default. Save the settings.php file and re-upload to the web server for production.

Step Five:
Testing the Drupal 8 + Redis Integration

In order to confirm the successful integration of Redis & Drupal 8 on the web server, navigate to the Status Report page at: /admin/reports/status

How to Host Drupal 8 Websites with Redis on VPS Plans

Administrators should see the “Connected, using the PhpRedis client” message under the REDIS section of the Status Report. Otherwise, use the command:


The Redis CLI Monitoring Tools will automatically diagnose the installation on the web server based on the default URL configuration for the Drupal 8 domain.

Conclusion: Redis NoSQL for High Traffic Drupal 8 Websites

In production, high traffic Drupal 8 web publishers see major gains in MySQL database query reduction which reduces the backend strain on web servers for more web traffic support. The PHP Redis integration extends the caching to PHP session variables.

Combined with Memcached, Zend Opcache, APC, NGINX, & Varnish Cache solutions, high performance Drupal 8 web servers will be most optimized for page speed requirements. Redis can easily be considered a default option for Drupal 8 hosting, running on both Apache & NGINX as well as Linux or Windows equally.

Check out these top 3 Drupal hosting services:

Was this article helpful?