Redis object cache can improve performance for some websites that perform heavy database queries. It reduces the number of queries to the database by caching results from previous queries, resulting in faster page load times and improved user experience for some database-heavy websites and applications.
However, if your site does not need Redis, we recommend not enabling it, as it can sometimes (but not always) degrade website performance on high-performance servers.
Secure, Isolated Redis for Multi-user Environments
Traditional Redis is insecure when used on servers with multi-user environments and shared hosting servers, as one user can easily access and modify another user's data stored in Redis.
We deploy isolated Redis instances for each user, which remain encapsulated and completely separate from other users' instances. One user cannot access or alter another user's Redis data, and one user's issues cannot impact another user's Redis instance, making it safe to use in multi-user and multi-website environments.
IMPORTANT!
Do not enable Redis in multiple plugins on the same website. Doing so can create conflict. If Redis is enabled in the LiteSpeed Cache for WordPress plugin, do not enable it in the Redis Object Cache plugin or any other plugin.
If you have multiple websites in the same cPanel/DirectAdmin account, specify a different "Redis Database ID" for each website to avoid key conflicts. You can set the "Redis Database ID" to any number from 0 to 7, e.g., 0 for the first website and 1 for the second, but not decimal values like 1.2. You can use a maximum of 8 databases (0 to 7) in a hosting account (cPanel/DirectAdmin account).
Before Install: Disable Conflicting Plugins
Only one plugin should use Redis. If you have another Redis plugin, disable and then uninstall it. Additionally, if any other plugin utilizes Redis, disable Redis in those plugins as well.
Step 1: Enable Redis Socket
cPanel:
Redis is integrated into the LiteSpeed Redis Cache Manager in cPanel:
- Go to cPanel > Redis Object Cache.
Or, cPanel > LiteSpeed Redis Cache Manager. - Click "Enable Redis Service" below "Redis Management".
Wait for it to be enabled.
Once enabled, a notification will appear near the top of the page saying, "Enabled Redis successful Created symlink". - Done!
DirectAdmin:
- Go to DirectAdmin > Redis.
- Set the toggle to "Enabled" or click "Enable Redis".
Once enabled, a "Success" message will appear near the bottom of the page. - Done!
Step 2: Enable Redis PHP Extension
- Go to cPanel > Select PHP Version > Extensions.
Or, DirectAdmin > Select PHP Version. - Checkmark [*] redis
Wait 15-40 seconds to enable the Redis extension.
Refresh the page to update its status. - Done!
Step 3: Enable Redis in WordPress
Redis can be enabled using "LiteSpeed Cache for WordPress", "Redis Object Cache (redis-cache)", or a similar plugin. Use only one plugin to avoid conflict.
Using LiteSpeed Cache (Recommended):
- Install LiteSpeed Cache for WordPress.
LiteSpeed Cache is a full-page cache with native CDN integration and support for dynamic content (WooCommerce, logged-in pages, etc.). It makes your website much faster and reduces resource consumption lower than Redis, even when Redis is disabled. - Go to WordPress Admin > LiteSpeed Cache > Cache > Object.
- Check if the Redis Extension status is enabled (next to Object Cache):
Redis Extension:Enabled
If not enabled, complete "Step 2: Enable Redis PHP Extension" above. - Set "Object Cache" to ON.
- Set "Method" to Redis.
- Enter the following details:
Host:/tmp/redis.sock
Port:0
Redis Database ID:0
Note 1:
The Redis Database ID should be a unique number for each website.
If you have other websites using Redis on the same hosting account (same cPanel/DirectAdmin account), the default value 0 is used for the first website.
For the next website, set it to 1 or any value up to 7, but not 0.
Note 2:
The Host path on DirectAdmin is different. Use the path mentioned below on DirectAdmin-based hosting accounts. - Click "Save Changes".
Connection test should now reflect the following (next to Object Cache):
Connection Test:Passed
If failed, complete "Step 1: Enable Redis Socket" above.
If "Connection Test" fails even after completing "Step 1" and "Step 2" above, refer to the Troubleshooting section below. - Done!
Or, Using Redis Object Cache:
The "Redis Object Cache (redis-cache)" plugin does not have any option to change the Redis path from the WordPress Admin:
- Install the Redis Object Cache (redis-cache) plugin.
- Find this line in your
wp-config.php
file:/* Add any custom values between this line and the "stop editing" line. */
- Add the following lines below the above line:
define('WP_REDIS_SCHEME', 'unix');
define('WP_REDIS_PATH', '/tmp/redis.sock');
define('WP_REDIS_DATABASE', 0);
Note 1:
WP_REDIS_DATABASE should be unique for each website. Use 0 for the first, 1 for the second, and so on up to 7.
Note 2:
WP_REDIS_PATH is different on DirectAdmin-based servers. Use the path mentioned below on DirectAdmin-based hosting accounts. - Wait about 5 minutes for PHP to be compiled. You should now be able to connect to Redis.
If you cannot, add the following lines below the above lines:define('WP_REDIS_HOST', '/tmp/redis.sock');
define('WP_REDIS_PORT', 0);
If you are still unable to connect to Redis, refer to the Troubleshooting section below. - Done!
Redis Socket Path on DirectAdmin
DirectAdmin uses a different path for the Redis Socket. You can view the path from DirectAdmin > Redis. You can also use the following:
Socket Path: /home/dausername/.redis/redis.sock
*Replace dausername
with your DirectAdmin username
.
Troubleshooting
If Redis cannot be enabled in WordPress after completing every step above, you might have invalid PHP paths in your .htaccess or .user.ini file. Refer to the following guide to fix it:
Fix incorrect PHP handler or session path