Using Redis as a persistent object cache for WordPress on cPanel

Procédure

What is Redis?

Redis is a very high-performance key-value storage service. Quite similar to Memcached, Redis has the advantage of being persistent: the data is not volatile.

Given the fairly simplistic nature of its data structure, and the fact that all the data is preloaded into memory when Redis starts up, searching and retrieving information from a Redis database using its unique key is much faster and less resource-intensive than retrieving the same information from a traditional database such as PostgreSQL or MySQL.

You can find out more about Redis on their official website.

Why and when should I use Redis as an object cache for WordPress?

The Redis object caching system is not to be confused with page caching systems such as Fastest Cache, LiteSpeed or WP-Rocket. Page caching systems cache an entire page that has already been built, whereas an object caching system allows you to cache certain elements of the site, such as an article, a comment, a product, etc.

An object cache system simply makes less of a demand on the MySQL database when building a page, while reducing response time, whereas a page cache system keeps a page completely built for later use. As a result, a Redis object cache system will not be beneficial for predominantly static sites such as blogs and storefront sites.

Only websites that are highly dynamic (their page content cannot be cached for long enough) are good candidates for object caching. This is particularly the case for certain ecommerce sites, sites with members' areas, discussion forums and certain blogs where the comment section is particularly active.

If your website has static content, you will be better off optimising page caching with Fastest Cache or LiteSpeed.

How do I activate Redis on cPanel?

The Redis service is available for all cPanel accounts on the default port (TCP 6379). For a PHP script to be able to communicate with a Redis server, it will need to be supplied with a suitable library. The most popular libraries include :

  • PhpRedis (written in C language, supplied as a PHP extension): to be activated via the cPanel interface
  • Predis (written in PHP, supplied as a PHP dependency that can be installed using the composer utility): to be installed using the composer command or, in most cases, already supplied inside your PHP script (usually in the "vendor" folder).

Depending on the PHP script you're using, you'll be able to use one, the other or both. The WordPress plugin we're going to recommend is compatible with both libraries.

Activating PhpRedis on cPanel

To activate PhpRedis, which is the PHP Redis extension, log in to your cPanel interface and click on"Select a PHP version" in the"Software" section.

Using Redis as a persistent object cache for WordPress on cPanel

Tick the"Redis" extension to activate it.

Using Redis as a persistent object cache for WordPress on cPanel

How do I use Redis as a persistent object cache on WordPress?

To use Redis as an object cache on WordPress, you will need to install the Redis Object Cache plugin. From your WordPress dashboard, go to"Extensions" then"Add".

Using Redis as a persistent object cache for WordPress on cPanel

Search for the"Redis Object Cache" plugin and click on"Install now".

Using Redis as a persistent object cache for WordPress on cPanel

Once the installation is complete, activate the plugin by clicking on the"Activate" button.

Using Redis as a persistent object cache for WordPress on cPanel

From your cPanel file manager, edit your wp-config.php file and add the following lines:

define( 'WP_REDIS_CLIENT', 'phpredis' ); define( 'WP_REDIS_SELECTIVE_FLUSH', true); define( 'WP_REDIS_PREFIX', 'monsite.com' );

Using Redis as a persistent object cache for WordPress on cPanel

  • The value of WP_REDIS_CLIENT allows you to choose the library used by the WordPress plugin to access Redis: phpredis or predis.
  • The value of WP_REDIS_SELECTIVE_FLUSH allows you to delete only the data with the prefix defined on WP_REDIS_PREFIX during a total cleanup of the Redis cache.
  • The value of WP_REDIS_PREFIX allows you to specify a key prefix for the data on your site (so that it does not conflict with other sites). It is important to specify a unique prefix for each site.

Once you've added these settings and saved the file, return to your WordPress dashboard. In Settings then Redis, activate the Redis object cache system:

Using Redis as a persistent object cache for WordPress on cPanel

Cache calibration options can be added to wp-config.php for more specific needs. For more information, please consult the plugin's official documentation.

How can I use Redis on WordPress with W3 Total Cache?

You can also use the WordPress plugin W3 Total Cache to cache the results of database queries. Note that this method is different from object caching. It is only recommended if a heavily used plugin does not use the WordPress object system (such as custom post types) to store and retrieve data.

1. Log into your WordPress Dashboard and go to"Extensions/Add".

Using Redis as a persistent object cache for WordPress on cPanel

2. Search for the"W3 Total Cache" plugin and click on"Install now".

Using Redis as a persistent object cache for WordPress on cPanel

3. Activate the plugin by clicking on the button.

Using Redis as a persistent object cache for WordPress on cPanel

4. Click on"Settings" below the plugin to access its configuration.

Using Redis as a persistent object cache for WordPress on cPanel

5. Go to the"Database caching" section, tick the"Database checkbox" box and choose"Redis" from the drop-down window. Finally, click on"Save settings and purge cache" to save your request.

Using Redis as a persistent object cache for WordPress on cPanel

Conclusion

You are now able toactivate and configure the Redis Object Cache plugin on your Wordpress site with your cPanel web hosting. Note that all Redis data is accessible to all users of the same cPanel server. As a result, it is imperative never to store sensitive information on Redis.

Don't hesitate to share your comments and questions.

Rate this article :

5/5 | 1 opinion

This article was useful to you ?

Article utileYes

Article non utileNo

Vous souhaitez nous laisser un commentaire concernant cet article ?

Si cela concerne une erreur dans la documentation ou un manque d'informations, n'hésitez pas à nous en faire part depuis le formulaire.

Pour toute question non liée à cette documentation ou problème technique sur l'un de vos services, contactez le support commercial ou le support technique

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

1mn reading

How do I configure Cloudflare on a website hosted on cPanel?

3mn reading

How do you use Memcached on your cPanel website?

4mn reading

Speed up your site with Fastest Cache - Cache Varnish

3mn reading

How can I use IpXchange to customise the IP of your domain?


Questions sur l'article
bersyl91 Il y a 664 days
Bonjour, J'amende ma question : j'ai bien trouvé l'onglet "Diagnostics" de l'extension Redis, mais cela ne m'avance pas beaucoup : Status: Non connecté Client: PhpRedis (v5.3.4) Drop-in: Valid Disabled: No Connection Exception: Connection refused
See the
1 answers
Benjamin-LWS - Il y a 661 days

Bonjour,

Merci de votre retour,

Le message "Connection refused" indique que l'extension Redis ne parvient pas à se connecter au serveur Redis.

Le problème rencontré peut-être dû à plusieurs facteurs, que nous ne pouvons pas déterminer via cette plateforme de Question.

Nous vous invitons donc à passer par notre système de support technique disponible depuis votre espace client, afin de vous apporter l'aide adéquate. (https://aide.lws.fr/a/268)

Cordialement, L'équipe LWS.

Utile ?
Fred Il y a 598 days
Je ne trouve pas redis dans mon Cpanel. Absent de ma rubrique Logiciels.
See the
1 answers
Benjamin-LWS - Il y a 590 days

Bonjour,

Merci de votre retour.

Grâce aux informations renseignées à l'ouverture de votre question, j'ai pu constater que vous ne possédez de formule cPanel.

Une formule cPanel est nécessaire pour bénéficier des fonctionnalités que vous souhaitez.

En savoir plus sur les formules cPanel disponible chez LWS : https://www.lws.fr/hebergement-cpanel.php

Je vous remercie de votre attention et reste à votre disposition pour toute autre question ou complément d'information.

Nous vous invitons à contacter notre service support à travers votre espace client, afin de vous apporter une aide si vous rencontrez des difficultés quelconque. (https://aide.lws.fr/a/268)

Cordialement, L'équipe LWS 

Utile ?

Ask the LWS team and its community a question