Install Redis to accelerate your WordPress website

Redis memory caching will accelerate your WordPress website and improve the website speed and performance dramatically. In this quick tutorial, I will show you how to install Redis and how to configure WordPress to use Redis caching.

What is Redis?

Redis is an Open Source, in-memory data structure store that can be used for caching and database storage. It can significantly improve your WordPress website speed and performance.

Why do I need Redis cache?

The Redis cache will help you keep up with Google’s recent algorithm changes and the fact that website speed and performance is now very important ranking factors for SEO.

If your website is slow and you don’t know how to fix it, we would be very pleased to provide you with our excellent SEO and Performance optimization service.

Requirements

Considering that this is server-side caching, you need to have SSH access to your VPS or root server. If you are using shared hosting, you will need to ask your hosting provider to install Redis caching for you. Then just skip to the part of the article that covers the configuration of WordPress.

In this tutorial, we will use CentOs as an example because it’s the operating system of choice for many hosters. The installation of Redis on Ubuntu or Debian is pretty much the same.

Installing Redis on Centos 7 / RHEL 7

Access your server via terminal using SSH.

Then type the following command to add EPEL repository if you are not using it already.

yum install epel-release

Now, just type the following command to install Redis.

yum install redis

Then we need to set the Redis to auto-start on the system boot, and to active it.

systemctl enable redis
systemctl start redis

The Redis is now installed and running.

Redis PHP extension (optional)

Now we can install the Redis PHP module by typing the following code inside the terminal.

(*) Note that this code example is for PHP 7.0, you will need to replace values php70 inside the code to match your currently installed PHP version, e.g. php72 for example.

cd /root
git clone https://github.com/phpredis/phpredis.git
cd phpredis
make clean
/opt/alt/php70/usr/bin/phpize
./configure — with-php-config=/opt/alt/php70/usr/bin/php-config
make
make install

Then edit your php.ini. (We are using Vi editor in this example, you can use any other text editor of your choice.)

vi /etc/php.ini

and add this line at the end of the file:

extension=redis.so

Test the connection to your Redis instance by typing the following command.

redis-cli ping

You should receive the PONG as an answer.

You can also check if the Redis is running properly with the systemctl command.

systemctl status redis.service

The results should look like this.

● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Sun 2020-09-06 00:20:42 CEST; 34 days ago
 Main PID: 951 (redis-server)
   CGroup: /system.slice/redis.service
           └─951 /usr/bin/redis-server 127.0.0.1:6379

You now have the Redis server and Redis PHP extension installed and waiting for connections.

Set up and configure WordPress to use Redis

Now we can start configuring WordPress to use the benefits of Redis caching.

Access your WordPress admin area and navigate to Plugins -> Add new. In the form at the right side type “Redis” and wait for the results.

Once the plugins are listed, you can choose between “Redis object cache” and “WP Redis“. Both plugins are fully capable to make your WordPress objects cached in memory using Redis.

Install Redis plugin for WordPress

Redis Object cache plugin

Once you install and activate Redis Object cache, navigate to WP admin -> Settings -> Redis. Here just click on the button “Enable Object Cache”.

WP Redis

This plugin has no options page and it’s working right out of the box. Once you install and activate the plugin it will start working automatically.

Redis CLI and flushing the database cache

One of the important things is also flushing the Redis database cache. The plugin “Redis Object cache” offers the option to manually flush the cache from Redis server.

You can use Redis CLI to wipe the cache. Access your terminal and type this command:

redis-cli FLUSHDB

You can also flush the cache from all databases:

redis-cli FLUSHALL

Redis CLI offers more options to configure the database flushing, please check the official Redis documentation for more.

Conclusion

After installing the Redis caching and setting up the plugin to use the Redis for caching WordPress objects, your website should work much faster.

You are also free to share your opinion on the Redis cache and setup or ask for help in the comments below.

Share this if it was helpful!
davor
davor

I'm Davor, aka. Worda, founder of EleTuts. I hope my articles and guides will help you achieve more with Elementor and WordPress.
My passion is WordPress, plugins and theme development and all-around software development

Articles: 63

Leave a Reply

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