LinuxWeb ServersWordPress

Install Redis Object Cache for WordPress on Ubuntu 22

Redis Object Cache in WordPress is a powerful object caching mechanism that enhances the performance of your WordPress site. Over 65% of the websites online today are powered by WordPress. Content Management Optimization is a huge part of running a WooCommerce site, Shopify store, or WordPress blog hosting. So there are many different types of caching like website caching which stores a copy of visited pages in cache. Which, in turn, makes them faster to load for repeat visitors. Another type is Object caching. There are two main options to choose from when you want to implement Object Cache—MemcacheD or Redis which is considered superior. Here we learn about Redis and how to install Redis Object Cache in LiteSpeed/OpenLiteSpeed Ubuntu 22 servers.

What Is Redis Object Cache?

  • Redis Cache is a persistent object cache backend powered by Redis.
  • It bridges your WordPress application and the Redis database, allowing you to store frequently accessed data in memory.
  • By doing so, it significantly reduces the need to query the database repeatedly, resulting in faster page loads.

How Does It Work?

  • When a user visits your WordPress site, various database queries are executed to retrieve content (such as posts, pages, and comments).
  • Redis Object Cache intercepts these queries and stores the results in memory.
  • Subsequent requests for the same data can then be served directly from Redis, bypassing the database altogether.

Key Features and Benefits:

  • High Performance: Redis is an in-memory data store, which means lightning-fast read and write operations.
  • Customizable: You can adjust connection parameters, configure replication, and even set up clustering.
  • Compatibility: Supports various Redis clients, including Predis, PhpRedis (PECL), and Relay.
  • Debugging and Logging: Easily monitor cache performance and troubleshoot issues.
  • Unit Tested: The plugin is thoroughly tested to ensure reliability.
  • Secure Connections: Supports TLS for secure communication.
  • Optimized for Plugins: Works seamlessly with popular plugins like WooCommerce, Jetpack, and Yoast SEO.

Install Redis Object Cache In WordPress Ubuntu 22

Recently we wrote about MariaDB Galera Database Replication and we now want to introduce Object cache to the cluster. We can see from the Litespeed WordPress plugin that there is no Object cache at the moment.

So we need to install Redis Object cache on each node in the cluster. Our cluster is running Ubuntu 22 so to install Redis run the commands below. This will also configure Redis to start on boot.

apt install redis-server

systemctl enable redis-server

The configuration file for Redis server is located at /etc/redis/redis.conf. Open up the file.

nano /etc/redis/redis.conf

Inside this file find the line supervised no and modify it to say supervised systemd. All you are doing here is telling Redis that it will be used with systemd. Restart the Redis server and display the status of the service.

systemctl restart redis-server && systemctl enable redis-server

Test Redis Server

So, to ensure Redis is functioning correctly drop into the Redis CLI with the below command.

redis-cli

In the redis-cli you will notice the local IP 127.0.0.1 followed by a port which is :6379. So issue the command ping and the response should be pong.

127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set test "Hello Ojbect Cache!"
OK
127.0.0.1:6379> get test
"Hello Ojbect Cache!"

Enable Redis Object Cache In LiteSpeed

To enable Redis in LiteSpeed PHP, install the PHP module and then create a redis.ini file at /usr/local/lsws/lsphp81/etc/php/8.1/mods-available/redis.ini.

apt install lsphp81-redis

nano /usr/local/lsws/lsphp81/etc/php/8.1/mods-available/redis.ini

; configuration for php redis
; priority=20
extension=redis.so

Finally, restart the LiteSpeed VPS Server and in the WordPress LiteSpeed Cache plugin you should now notice Redis cache is enabled.

install redis object cache ubuntu php

Repeat the process on all nodes in your cluster if you are Load-balancing traffic.

Related Articles

Leave a Reply

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

Back to top button