How to Install and Use Redis with WordPress

|

|

This text guides students on how to configure WordPress to use Redis for object caching, thereby speeding up database queries and PHP dynamic calls. Instructions cover how to install the latest Redis server on Ubuntu Linux, setting up the Redis eviction policy, configuring WordPress with Redis, and installing the Redis Object Cache Plugin on WordPress.…

This post shows students and new users steps to configure WordPress to use Redis for object caching to speed up database queries and PHP dynamic calls.

When running WordPress sites, you should always look for ways to enhance the sites’ performance by enabling caching and other performance-boosting configurations.

Installing and using Redis with WordPress can greatly improve the performance of your website. Redis is an in-memory data structure store used as a database, cache, and message broker. By caching database queries and PHP dynamic calls, Redis reduces the number of times WordPress has to access the database, which can help speed up your website.

This can lead to faster page load times, better user experience, and improved search engine rankings. With the steps outlined in the previous message, you can easily configure WordPress to use Redis and take advantage of its benefits.

How to install the latest Redis server on Ubuntu Linux

After installing WordPress, run the commands below to install the latest version of Redis.

The version of the Redis server that comes with Ubuntu by default isn’t the latest. To install the newest version, add the PPA below and install it from there.

To do that, run the commands below:

sudo apt-get install software-properties-common

Once that package is installed, run the commands below to add the PPA containing the latest Redis version.

sudo add-apt-repository ppa:chris-lea/redis-server

After adding the repository, run the command below to install Redis.

sudo apt-get update
sudo apt-get install redis-server php-redis

Verify that you have version 4 of Redis installed with the following command:

redis-server --version

You should see the Redis version installed on your system.

How to set up the Redis eviction policy

Now that Redis is installed run the commands below to open its configuration file.

sudo nano /etc/redis/redis.conf

Then, uncomment the lines below to allow memory and an eviction policy. You’ll have to scroll through the lines to find these. Then, set them up as shown below:

maxmemory 256mb
maxmemory-policy allkeys-lfu

Finally, save the file and exit.

When you’re done, run the commands below to restart Redis and PHP; if you’re running Apache2, restart Apache2 and the Redis server.

sudo systemctl restart redis-server
sudo systemctl restart php7.2-fpm

How to configure WordPress with Redis

After the above steps, run the commands below to open the WordPress wp-config.php file in your WordPress root directory.

sudo nano /var/www/html/wordpress/wp-config.php

Then, add these lines below the WordPress unique Keys and Salts section.

define( 'WP_CACHE_KEY_SALT', 'example.com' );
define( 'WP_CACHE', true );

After that, save the file and exit.

How to install Redis Object Cache Plugin

The final step is to install the WordPress Redis Object Cache Plugin. To do that, navigate to the plugin page and install it in WordPress.

After installing, activate and enable the plugin. When you’re done, go to the plugin settings page, and if everything is configured correctly, you should see something similar to the image below:

That should do it!

Your WordPress setup should now use Redis object caching to help speed up your site.

Conclusion:

This post showed you how to configure WordPress with a Redis caching server to improve performance. Please use the comment form below if you find any errors above or have something to add.

Like this:



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.