Redis is a great way to speed up your WordPress sites. By using Redis to cache various database queries, your site can run faster than ever before and even save you money by using less server resources.
In this article, we'll show you how to configure Redis using the Redis Object Cache plugin to cache database queries within WordPress.
Considerations
The steps within this article only apply to situations when our automatic configuration of the Object Cache Pro plugin cannot be used, such as sites that are not hosted with Pagely.
If you are hosting on a Pagely VPS, we recommend that you follow the steps outlined in our How To Use Redis Object Caching in WordPress tutorial.
Configuring the Redis Object Cache Plugin
- Begin by accessing your VPS via SSH.
- Next, access the site that you want to activate Redis caching on.
cd ~/sites/example.com
- Next, edit your wp-config.php file to include the following lines:
define('WP_REDIS_PORT', 6380); define('WP_CACHE_KEY_SALT','MY_SITE_NICKNAME_HERE');
- If you're on one of our High Availability plans, you'll also need to set the Redis Host. If not, you can skip to step 5.
On the primary server, run the ifconfig command to get your primary server's IP (10.x.x.x), then add the following to your wp-config.php file:
define('WP_REDIS_HOST', '10.x.x.x');
- Next, install and activate the Redis Object Cache plugin from the WordPress repository. This can be done with WP-CLI using the following command:
wp plugin install redis-cache --activate
- Now that the Redis Object Cache plugin is installed and activated, log into your WordPress admin dashboard and use the left side navigation menu to go to Settings, then to Redis.
- Finally, verify that the Redis Object Cache plugin has the proper settings (Port is set to 6380 and the Cache Key Prefix is populated), then click Enable Object Cache.
Note: It is extremely important that your port is set properly to 6380. If not, you will lose important configuration data and cause your site(s) to become unavailable until that data gets reapplied.
That's it! Redis caching is now enabled and ready to go! For further information on optimization your WordPress site, take a look at our WordPress optimization guide.