WordPress

How to Install and Configure Redis Object Cache for WordPress

 · 

How to Install and Configure Redis Object Cache for WordPress

The Role of Redis in WordPress Performance

In the modern web world, speed is a vital factor for both user experience and SEO (Search Engine Optimization). Due to their dynamic nature, WordPress sites send numerous queries to the database with every page request. This causes database bottlenecks and slow loading times, especially on high-traffic sites. Redis Object Cache is an open-source, in-memory data structure store that solves this problem by caching database query results in RAM.

What is Object Caching?

Object Caching is the process of storing the results of complex database queries. When a user visits your site, instead of WordPress pulling the same data from the database repeatedly, it retrieves it quickly via Redis. This minimizes disk I/O operations and significantly reduces CPU usage.

Step 1: Installing Redis on the Server

Before using Redis with WordPress, the Redis service must be installed on your server (for Ubuntu/Debian-based systems). Connect to your terminal via SSH and run the following commands:

sudo apt update
sudo apt install redis-server
sudo systemctl enable redis-server

To check if Redis is running, use this command:

redis-cli ping

If everything is correct, you should receive PONG as the output.

Step 2: Installing the PHP Redis Extension

For WordPress to communicate with Redis, the PHP Redis library must be installed on your server. Use the following command according to your PHP version (e.g., PHP 8.1):

sudo apt install php8.1-redis
sudo systemctl restart php8.1-fpm
sudo systemctl restart apache2 # Or nginx

Step 3: Installing the WordPress Redis Object Cache Plugin

Once the server-side preparations are complete, go to your WordPress admin dashboard:

  • Go to Plugins > Add New.
  • Search for Redis Object Cache and install/activate the plugin developed by Till Krüss.
  • Click the "Enable Object Cache" button on the plugin settings page.

Step 4: Configuring the wp-config.php File

If you are hosting multiple WordPress sites on the same server, it is recommended to add a unique salt to your wp-config.php file to prevent cache collisions:

define('WP_CACHE_KEY_SALT', 'your-site-unique-key');
define('WP_REDIS_DATABASE', 0); // You can choose a different number (0-15) for each site

Conclusion and Performance Analysis

After installing Redis, you can monitor database query times using tools like Query Monitor. You will typically notice a 50% to 80% reduction in database load and a visible improvement in page load speeds. As a Cloud Architect, I recommend making Redis usage a standard procedure for high-traffic corporate websites.

← Blog Listesine Dön