For AI agents: the complete documentation index is available at https://docs.ovhcloud.com/pl/llms.txt, the full documentation bundle is available at https://docs.ovhcloud.com/pl/llms-full.txt, and this page is available as Markdown at https://docs.ovhcloud.com/pl/guides/public-cloud/databases/valkey-tuto-wordpress.md.

Boost your WordPress CMS with caching with Public Cloud Databases for Valkey

Pokaż jako Markdown

Boost the performances of your WordPress CMS with a Valkey service

Objective

Do you have a CMS website or blog, perhaps powered by WordPress? Learn how to speed up page load times and SQL queries using a Valkey service! In this tutorial, we will set up a Valkey service for your CMS data. All users, even administrators and especially visitors, will directly benefit from a better performance of the website.

Warning

OVHcloud provides services for which you are responsible for their configuration and management. You are therefore responsible for their proper functioning.

This tutorial is designed to help you as much as possible with common tasks. If you are having difficulty performing these actions, please contact a specialised service provider and/or discuss it with our community of users. OVHcloud cannot provide you with technical support in this regard.

CMS platform

For this tutorial we propose to use the WordPress CMS, running on Linux Ubuntu with MySQL as the main database. To get the object cache we will use a Public Cloud Database for Valkey and the WordPress plugin Redis Object Cache, which is compatible with Valkey.

Warning

This tutorial will show you how to use one or more OVHcloud solutions with external tools, and will describe the actions to be carried out in a specific context. Please remember to adapt these actions to fit your situation.

If you encounter any difficulties performing these actions, please contact a specialist service provider and/or discuss the issue with our community. OVHcloud cannot provide you with technical support in this regard.

Remember to back up your files prior to making any changes.

Requirements

This tutorial requires:

  • A running WordPress
  • A WordPress administrator account to install a plugin
  • A PHP client supported by the plugin (in this tutorial: PhpRedis)
  • A Valkey service running on your OVHcloud Public Cloud Databases (this guide can help you to meet this requirement)

Instructions

Tutorial technical environment

This tutorial is based on the following software components:

  • Linux Ubuntu 24.04 LTS / Apache 2.4 / PHP 8.3 / MySQL 8.0
  • WordPress: 7.1
  • PhpRedis: 5.3.7 (package php-redis of Ubuntu 24.04)
  • Redis Object Cache: 3.0
  • Valkey: one of the versions listed in the Valkey capabilities guide

The screenshots were taken with earlier releases of WordPress and of the plugin: your interface may differ slightly.

Configuring your CMS: WordPress

If you need to install WordPress, please refer to the official guide: WordPress How To Install.

Once done, we will set up the WordPress backend correctly. For the next steps, let's consider that you have an up and running WordPress system on a LAMP (Linux, Apache, MySQL, PHP) platform.

PHP client: PhpRedis

As WordPress is based on PHP, we will need a PHP client compatible with Valkey. We propose to use one of the main PHP clients: PhpRedis.

As TLS is required to secure the connection to the OVHcloud Public Cloud database for Valkey, we have to use the v5.3.x release of PhpRedis or above.

Please check that PhpRedis is installed, with a compliant release:

  • If you do have SSH access to your WordPress server you can use the following command:
dpkg -l php-redis

In case it is not available on your system, please install it:

sudo apt install php-redis
sudo systemctl restart apache2
  • If you don't have SSH access to the system, use the phpinfo() function and do a search on the redis module (the PhpRedis extension) as in the following example:
PhpRedis module in PHPInfo

WordPress plugin: Redis Object Cache

There are multiple object cache plugins that could be used to integrate a Valkey service. You can search them directly in the Plugin menu. For this tutorial we decided to use the most popular one: Redis Object Cache. Click on the Install Now button:

Search Redis Object Cache plugin

You can get more information related to this WordPress plugin at the official WordPress plugin documentation - Redis Object Cache.

Configure WordPress to connect to the Valkey service

Modify wp-config.php

Before activating the Redis Object Cache plugin, it is required to configure the Valkey service connection parameters. By default, this plugin looks for a service hosted on the same server as your WordPress. It's not our case scenario here, since the Valkey service is hosted in OVHcloud Public Cloud Databases.

We will follow the official plugin documentation to define the remote server: Redis Object Cache configuration. This has to be done in the WordPress configuration file (wp-config.php located in /var/www/wordpress/ in our example) by adding the following lines, replacing <host>, <port>, <username> and <password> with the values of your service (host and port are displayed in the Connection information section of the Dashboard tab of your service in the Control Panel):

define( 'WP_REDIS_CLIENT', 'phpredis' );
define( 'WP_REDIS_SCHEME', 'tls' );
define( 'WP_REDIS_HOST', '<host>' );
define( 'WP_REDIS_PORT', <port> );
define( 'WP_REDIS_PASSWORD', [ '<username>', '<password>' ] );
define( 'WP_REDIS_SSL_CONTEXT', [
    'verify_peer' => true,
    'verify_peer_name' => true,
]);
define( 'WP_REDIS_PREFIX', 'myvps_' );

The tls scheme is mandatory: the Valkey service refuses unencrypted connections. The server certificate is signed by a public certification authority, so no certificate needs to be downloaded: keep the certificate verification enabled (verify_peer and verify_peer_name set to true) and never disable it.

The user defined in WP_REDIS_PASSWORD must be allowed by its ACL to read and write the keys used by the plugin (for example the key pattern myvps_* if you use the prefix above).

Key prefix

The key prefix (WP_REDIS_PREFIX, which replaces the deprecated WP_CACHE_KEY_SALT constant) is not mandatory, especially if you have only one application using a Valkey service, but if you have several WordPress sites, it will be useful to determine what-pushes-what.

Set an eviction policy suited to caching

By default, the valkey_maxmemory_policy advanced parameter of your service is set to noeviction: when the memory is full, Valkey rejects new writes and the plugin can no longer store objects in the cache. For a cache use case such as this one, we recommend setting this parameter to allkeys-lru, so that Valkey evicts the least recently used keys when memory is full.

To modify this parameter, follow the guide Configure the advanced parameters for Public Cloud Databases. Changing the advanced configuration may restart the service.

Check that authorised IPs are updated

Do not forget to add the IP address of your WordPress server to the authorised IPs of the Valkey service. To do so, follow the guide Configure incoming connections of a Public Cloud Databases for Valkey service.

Activate and enable the plugin

Now all installation and configurations are done. So let's activate the plugin.

Activate Redis Object Cache Plugin

Then enable the object cache functionality.

Enable Redis Object Cache

If you run into any problems enabling the Redis Object Cache plugin, start your investigation by looking at the information available in the Diagnostics tab on the Plugin Settings (connection status, client, errors and the values of the WP_REDIS_* constants).

Additional parameters

Please find below more documentation on the additional available parameters that you might want to use to optimise your Valkey service usage:

Checking performance boost

Validate that cache is populated

If you can use a CLI to query the Valkey service (see How to connect to a Valkey service with CLI), you can check that information has been added to it after browsing some WordPress pages.

In our case:

valkey-cli --tls -u valkeys://<username>:<password>@<host>:<port>
<host>:<port>> SCAN 0
1) "480"
2) 1) "myvps_wp:post_meta:782"
2) "myvps_wp:post_meta:418"
3) "myvps_wp:terms:13"
4) "myvps_wp:site-options:1-notoptions"
5) "myvps_wp:options:alloptions"
6) "myvps_wp:post_meta:905"
7) "myvps_wp:options:notoptions"
8) "myvps_wp:posts:get_page_by_path-83503918bbdb048f39fd1d3e462c8251-0.24924400 1637188954"
9) "myvps_wp:useremail:admin@example.com"
10) "myvps_wp:terms:3"

Install a query monitoring plugin

If you want to have more information about how the cache has impacted the performance, you can measure the gain in response delay directly with your browser. You can also see more details using an additional WordPress plugin like Query Monitor.

Example of performance boost with a basic WordPress site

Using a simple WordPress site populated with poor content and a very limited number of posts, let's take a look at the improvement.

We will look at the number of database requests for both cases: with and without the cache enabled.

Without the cache, there is a total of 15 database queries taking 0.0235s.

With the cache, there is a total of 2 database queries taking 0.0043s.

Two main benefits using a Valkey service

As seen, using a Valkey service you will see a performance gain for your CMS. It will be even more efficient as soon as your site stores more and larger data. You will also directly benefit from the fact that the MySQL server will be less stressed with the load/concurrent accesses, which will offer the opportunity to handle more and more users.

Go further

Join our community of users.

We want your feedback!

We would love to help answer questions and appreciate any feedback you may have.

For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.

Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our databases service!

Czy ta strona była pomocna?