2.14.1.2.5. Setting up Redis in WordPress
For use Redis in WordPress, you need to install and configure one of the specialized plugins.
Redis Object Cache
- Openup site admin panel.
- Install and activate the plugin Redis Object Cache.
- Edit site config file
wp-config.php
and add to its beginning right after<?php
such lines (in the second line instead ofexample
substitute hosting account name, in which the site is located, 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');
- In the admin panel of the site, go to the section «Settings → Redis» and press «Enable Object Cache»:If everything is in order, at the top of the section in the line «Condition» should display «Connected»:
- Check the site is working.
W3 Total Cache
- Openup site admin panel.
- Install and activate the plugin W3 Total Cache.
- Go to section «Performance → General Settings»:
- In the block «Object Cache»:
- In line «Object Cache» turnon «Enabled».
- In line «Object Cache Method» choose «Redis».
- Save your changes.
- Go to section «Performance → Object Cache»:
- In the block «Advanced»:
- In field «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 site admin panel.
- 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 plugin directory in the WordPress plugins directory.
- Edit site config file
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 hosting account namewhere the site is hosted):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: