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. 

  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

How to Hide Your NGINX Server Version.

Sometimes hackers target your server with a technic called banner grabbing. Usually, banner...

Do You Offer VPS with 8 vCPU Cores?

No, we do not provide VPS with 8 vCPU cores. We provide VPS with maximum 4 vCPU cores. This is...

How to install MongoDB version 4.0 on Centos 7?

MongoDB is an open-source and free Database service. It is a NoSQL Database and it is different...

How to create users and groups in CentOS7?

Once the Linux system is configured, adding and removing users is one of the most basic tasks...

How to upgrade MySQL/Maria DB in WHM/cPanel?

Note: These steps will work only with the cPanel version 88 and later. Please refer to the below...