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.

  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', '');
  10. To create a persistent cache with the Redis object cache plugin, add the below line after the define('WP_CACHE_KEY_SALT', ''); 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 to Enable Plaintext Authentication in Dovecot?

Dovecot is an Open source IMAP or POP3 server used to create light-weight and high-performance...

How to flush DNS cache on linux?

DNS is responsible for resolving website names into their respective IPs. Whenever you visit a...

How to change the timezone on Ubuntu 18.04 Server?

You can perform the below steps using root or sudo users. Check your current timezone by...

How to enable sFTP in a Linux VPS?

The SSH File Transfer Protocol (SFTP), also known as the Secure File Transfer Protocol, enables...

How to place an order for Linux VPS hosting?

Step-1: First, select your desired Linux VPS Hosting plan with your desired billing cycle...

  • 0 Users Found This Useful

Was this answer helpful?