How do you use Memcached on your cPanel website?

Procédure

What is Memcached?

Memcached is an object cache system in RAM memory. It is used to temporarily store frequently used data, such as the results of SQL queries, dynamic objects or binary data, so that they can be retrieved quickly without having to recalculate them each time a page is loaded.

The principle is simple: the data is stored directly in memory, allowing ultra-fast access. This is ideal for relieving the load on your database and improving the overall performance of your site, particularly for dynamic pages (shopping baskets, searches, comments, etc.).

⚠️ Limits to be aware of: As the data is stored in RAM, it is volatile. This means that it is lost as soon as the Memcached service is restarted or the server is rebooted.

What are the benefits for my site?

Even if your cPanel LWS package already includes a high-performance static page caching system (via the Fastest Cache module, activated by default), some areas of your site cannot be cached in the traditional way.

This is particularly true of dynamic pages such as shopping baskets, instant messaging systems, members' areas, comment threads, product search or filter modules, real-time news lists, etc.

This content changes very frequently and therefore cannot be fully cached. If they are loaded each time from the database (MySQL or PostgreSQL). This can slow down the display of your pages and unnecessarily overload the database server.

This is where Memcached comes into its own. It allows you to temporarily store certain dynamic data in memory, without freezing the entire page. For example, the names of the most popular products, their prices, the results of a complex query, etc.

So instead of restarting an SQL query on each visit, this data is read directly from memory. The result: your site is faster, your visitors have a better experience and your database is under less strain.

How do I use Memcached on PHP?

There are two different PHP extensions that can be used to enable a PHP script to communicate with a Memcached server: memcache and memcached. It is important to check with the author of your script to find out which of the two is used by your site. To activate one of them :

1. Connect to your cPanel interface and click on"Select a PHP version" in the"Software" section.

How do you use Memcached on your cPanel website?

2. Tick"memcache" or"memcached" as required.

How do you use Memcached on your cPanel website?

That's it. You can now connect to the memcached servers from your PHP scripts. An instance of memcached is available by default on your cPanel account. Here are the connection details:

  • Host: localhost
  • Port: 11211 (tcp)

How to configure Memcached on WordPress with LWS Optimize (recommended method)

The easiest and most effective way to use Memcached on WordPress hosted by LWS (cPanel package) is via the LWS Optimize plugin, developed specifically for our customers.

Automatic configuration steps :

1. Go to Extensions > Add from WordPress administration.

How do you use Memcached on your cPanel website?

2. Search for LWS Optimize, then install and activate the plugin.

3. Go to the extension settings in the side menu.

4. In the "Caching" tab, activate the Memcached Object Cache option.

How do you use Memcached on your cPanel website?

The service is automatically configured.

Advantages of this method:

  • Simple: No line of code to modify
  • Fast: Configuration in just a few clicks
  • Automatic: LWS Optimize detects which services are enabled on the server
  • Optimised: Native integration with cPanel LWS hosting
  • Bonus: LWS Optimize is not limited to Memcached. The plugin also offers other caching systems, automatic preloading and purging, lazy loading, optimisation of CSS, JS and HTML files, advanced image processing, etc...

Recommended for all WordPress sites hosted by LWS: If you're looking for the best performance without the hassle, this is the method for you.

How can I use Memcached as an object cache on WordPress with Memcached Object Cache?

WordPress already has an object cache ecosystem that allows plugins and themes to ask WordPress to store the result of a complex MySQL query in memory. This works with the WP_Object_Cache class. By using memcached as a storage space for WP_Object_Cache, WordPress can take advantage of memcached's performance.

The"Memcached Object Cache" WordPress plugin allows you to do this with the memcache PHP extension, which should be activated beforehand (see previous paragraph). To install it, download the plugin's object-cache.php file and place it in your website's wp-content folder ( using FTP or the cPanel file manager):

How do you use Memcached on your cPanel website?

Next, you will need to fill in a cache key so that your website knows which data on memcached is its own. This is done by adding the line"WP_CACHE_KEY_SALT" to wp-config.php:

How do you use Memcached on your cPanel website?

And that's it.

How do I configure MemCached on WordPress with W3 Total Cache?

1. Connect to your Wordpress interface and click on"Extension/Add" to install W3 Total Cache.

How do you use Memcached on your cPanel website?

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

How do you use Memcached on your cPanel website?

3. Click on"Activate".

How do you use Memcached on your cPanel website?

4. Look for the plugin in the list of plugins and click on"Settings" below it.

How do you use Memcached on your cPanel website?

5. Go to the"Database caching" section, tick the"Enable" box and enter"memcached" in the"Database cache method" section. Finally, click on"Save setting and purge cache" to save your request.

How do you use Memcached on your cPanel website?

You can perform the same operation for the"Object cache" section. The Object cache allows you to cache only the results of database objects.

How do I configure MemCached on Prestashop?

1. Connect to your Prestashop dashboard, click on "Advanced settings" and then on"Performance".

How do you use Memcached on your cPanel website?

2. Go to"Cache", click on "Yes" then choose"memcache" or"Memcached" depending on the extension you activated when selecting your PHP version. Finally, click on"Save" to save the request.

How do you use Memcached on your cPanel website?

Conclusion

You are now able to configure Memcached on your cPanel hosting package for WordPress or Prestashop. However, it should be noted that all data on Memcached is accessible to all users on the same cPanel server as yours. For this reason, it is imperative that you never store sensitive information on Memcached.

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?

4mn reading

Using Redis as a persistent object cache for WordPress on cPanel

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?


Ask the LWS team and its community a question