How To Configure Redis Caching to Speed Up WordPress on Ubuntu 18.04?

Redis is an open-source in-memory data structure store. It can be used as a DB and cache. It supports various data structures and can be used as a DB server.  You can use Redis with a relational database like MYSQL to speed up your website. 

In this article, we will configure Redis as a cache on a Wordpress website. It will load your Wordpress website faster. Redis will optimize the time-consuming database queries using its cache. 

A Default Wordpress page website without Redis can load around 800 ms and with Redis, you can lower it down to around 450 ms.

How does caching work?

When the WordPress page loads for the first time, a database query will be performed on your server. Redis will remember or cache the same query. Now, when another user tries to load the same Wordpress page, the results will be provided from Redis without querying to the database. It results in faster performance of your website. The object cache of Redis will cache the SQL queries which are required to load the wordpress pages.

Let us start with installing Redis on Ubuntu 18.04 server. 

  1. Run the below update command at the first step.

    sudo apt update
  2. Install Redis with the below command.

    sudo apt install redis-server
  3. Once Redis is installed, we will need to configure it as a cache.

  4. Add the below line at the end of your redis.conf file. Use the below command to perform this action. 

    maxmemory 256mb
    maxmemory-policy allkeys-lru
  5. Save and Close the redis.conf file. 

  6. Now, we will download the object-cache.php script file. It is a third-party script. You can read the comments to see how it works.

    wget http://demovpstest.com/object-cache.php/
    
  7. Move this file to /wp-content folder of Wordpress installation using the below command.

    sudo mv object-cache.php /var/www/html/wp-content/
  8. We will enable the cache settings in your Wordpress config file. To do this edit the wp-config.php 

    nano /var/www/html/wp-config.php
  9. Add the below line after the * Authentication Unique Keys and Salts. Section:

    define('WP_CACHE_KEY_SALT', 'yourwebsite.com');
  10. To create a persistent cache with the Redis object cache plugin, add the below line after the define('WP_CACHE_KEY_SALT', 'yourwebsite.com'); line.

    define('WP_CACHE', true);
  11. Save and close the file.

  12. Let us restart the Redis and Apache file. 

  • Restart Redis:

    sudo service redis-server restart
  • Restart Apache

    sudo service apache2 restart

This is it! Your WordPress website is now using Redis caching. Your Wordpress web page will load much faster now. 

Related Articles

How Do I Check Bandwidth Utilization of VPS?

Windows VPS To check/monitor usage of each Windows VPS, we have installed bandwidth meter tool...

How To Add A New IP Address In Virtualmin?

You can add an IP Address via Networking Module directly with virtualmean. To do this, you need...

Do you have any limits for setting up Cron jobs or schedule tasks?

Windows Shared Hosting Plans:We do not offer cron jobs in Windows shared hosting plans. Linux...

How to Setup MySQL Master-Slave Replication on RHEL 7?

In MySQL Replication process, one server data is automatically copied to another backup server in...

How to Apply Linux Kernel Security Patches? Manually and Automatically without reboot?

As we know, we do receive Linux kernel updates time and time again and it is essential to update...

  • 0 Users Found This Useful

Was this answer helpful?