2.13.1.2.5. Setting up Redis in WordPress
So that WordPress can use Redis, you need to install and configure one of the specialized plugins.
Redis Object Cache
- Openup Adminpanel site.
- Install and activate the plugin Redis Object Cache.
- Edit config file site
wp-config.php
and add to its beginning right after<?php
such lines (in the second line instead ofexample
substitute title the hosting account in which the site is hosted, in the third — instead ofexample
substitute a unique prefix for storing data in Redis, which is important when using Redis for multiple sites):define('WP_REDIS_SCHEME', 'unix'); define('WP_REDIS_PATH', '/home/example/.system/redis.sock'); define('WP_CACHE_KEY_SALT', 'example');
- Check the site is working.
W3 Total Cache
- Openup Adminpanel site.
- Install and activate the plugin W3 Total Cache.
-
- Against "Object Cache" check the box next to "Enabled".
- Against "Object Cache Method" choose "Redis".
- Save your changes.
- In the block "Advanced":
- Against "Redis hostname:port / IP:port" indicate
/home/example/.system/redis.sock
(insteadofexample
substitute hosting account namewhere the site is located) and click "Test":If everything is in order, a green inscription should be displayed "Test passed":
- Save your changes.
- Follow the same steps for "Page Cache" and "Database Cache".
- Check the site is working.
Object Cache Pro
Paid plugin
You can purchase a license for official website.- Openup Adminpanel site.
- Install and activate the Object Cache Pro plugin (installation is performed either by downloading the archive with the plugin through the WordPress admin panel, or by manually placing the plugin directory in the WordPress plugin directory).
- Place the plugins directory in the WordPress plugins directory.
- Edit config file site
wp-config.php
and add lines like this to it (in the second line, instead of<your-license-token>
substitute your license token, in the third line — instead ofexample
substitute title hosting account that hosts the site):define('WP_REDIS_CONFIG', [ 'token' => '<your-license-token>', 'host' => 'unix:///home/example/.system/redis.sock', 'database' => 0, // change for each site 'maxttl' => 86400 * 7, 'timeout' => 1.0, 'read_timeout' => 1.0, // 'prefetch' => true, // 'split_alloptions' => true, 'debug' => false, ]); define('WP_REDIS_DISABLED', false);
- In the WordPress dashboard, find the widget "Object Cache Pro" and press "Enable Object Cache"... If everything is in order, it should be highlighted "Status: Connected".
- Check the site is working.
Video
Connection Redis by using Redis Object Cache and W3 Total Cache: