Redis is an open-source application, and it helps to store in-memory data structures, used as databases, for object caching, and more. You can configure Redis Object Cache for WordPress to get maximum performance and speed.
Object caching is great for dynamic websites such as websites based on WordPress and other self-hosted CMS. On these platforms, content is frequently added and updated, in comparison to static.
When visitors return to your site, it loads much faster than before, loads faster even if you make changes or update content, thanks to the object cache.
Before configuring that you must know, what is Object Caching and how it works. And we are seeing how it is going to speed up your WordPress website. So, let’s start.
What is Object Caching?
Object caching is a type of caching, and it performs server-side. And this means the caching is handled at the server level and isn’t controlled by the front-end user.
Object cache stores data structures and database queries when first time loaded. When the visitor visits again (or requests the query again), the object cache serves data from the cache, without quired from the database. So, it reduces the high load on the database and performs better on the user end.
Configuring Redis as Object Cache
It is necessary to have installed Redis on your server. If you are using shared hosting with cPanel, then in this tutorial you will find out how you can check, if Redis is installed on not.
Configure Redis for WordPress on VPS
After installing Redis on Linux VPS (Ubuntu or Debian), you must follow these steps to successfully configure the object cache on WordPress.
Edit redis.conf
the file using the following command:
sudo nano /etc/redis/redis.conf
Add these lines at the end of the redis.conf file:
maxmemory 256mb maxmemory-policy allkeys-lru
Save the redis.conf file using CTRL+X and type Y and hit enter key on the keyboard.
Redis Cache Backend PHP Script for WordPress
This is optional, and instead of the script, you can use the functional “Redis Object Cache” or “LiteSpeed Cache” WordPress plugin.
Perhaps, it is a single PHP file (open source) developed by Eric Mann, you can download it from Digital Ocean’s asset server, using the following command:
wget https://assets.digitalocean.com/articles/wordpress_redis/object-cache.php
Move the PHP file to /wp-content directory of WordPress
sudo mv object-cache.php /var/www/html/wp-content/
Depending on your server configuration or WordPress installation, your location may be different from the example, so use commands as your specific directories.
Edit wp-config.php for configuring the Redis object cache
sudo nano /var/www/html/wp-config.php
Add this line of code end of the Authentication Unique Keys and Salts Section:
define(‘WP_CACHE_KEY_SALT’, ‘eduature.com’);
Here on example.com, you must palace your domain name. And you should make sure that you have also this line define(‘WP_CACHE’, true); on the wp-config.php file. If not, you can add this line with the salt key.
Now, to save the modification press CTRL+X and type Y, and hit enter on the keyboard.
Restart Redis and Apache
Restart Redis Server:
sudo service redis-server restart
Restart Apache Web Server:
sudo service apache2 restart
Configure Redis for WordPress on cPanel
Configuring the Redis object cache on cPanel is the easiest method. If you are using any VPS or Dedicated hosting with cPanel, most shared hosting comes with cPanel for giving better user experiences.