Install and Enable Redis Object Cache for WordPress on Debian Linux

Published in

on

WordPress has an inbuilt object cache that it uses to save on the trips to the database, but, it’s a non-persistent object cache. By using a 3rd party persistent object cache like Redis, we can reduce the load of database and cache as much as dynamic queries that goes to database every single time.

Let’s see how to install and enable Redis object cache.

Redis

Before you proceed ahead, I assume that you know how to manage an unmanaged server and have basic knowledge of command line. Don’t try unnecessary things.

First, install the necessary software.

We need to install Redis, it is a source-available, in-memory storage, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.

sudo apt install redis

Once it is installed, it will be start and enabled itself automatically for reboot.

Now we need to set a memory limit to it, otherwise it will use all resources whatever it gets. For that, you need to go into redis-cli and set a new limit.

sudo redis-cli

A message prompt will open there to communicate with Redis. Just ask itself what is the default maximum memory limit, if it is 0 (unlimited), then set some limit.

127.0.0.1:6379> config get maxmemory
1) "maxmemory"
2) "0"
127.0.0.1:6379> config set maxmemory 128M
OK

*Do not try to set a limit when everything is running after full setup.

Once you see the OK message, you are good to go for the next step.

Now we need to install supported PHP extensions so that our dynamic CMS can handle all those requests which are passed by Redis Object Cache.

sudo apt install php8.3-redis

Make sure you replace the PHP version with yours.

Now just restart or reload the PHP and move to the next step.

Login to your WordPress’s admin dashboard and install a plugin: Redis Object Cache.

Once plugin in install and activated, navigate to plugin settings and click on enable.

As soon as you enable it, your WordPress will connect to Redis and run the object cache. It will also leave a drop-in file to wp-content folder that has all configs to manage everything like cache, flush, etc.

My opinion about using object cache with WordPress! I do not recommend using Redis Object Cache for blogs and normal websites, as the benefit is less and NGINX’s FastCGI Cache will work faster with less hardware. But if you have a website which is complex in nature like membership, forum, or some ecommerce then using object cache makes sense. It is because they are more database intensive and by using object cache you cache the repetitive queries and save more room for user load.

Leave a Reply

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