Tag Archives: Memcached

Verifying The Presence Of Required PHP Libraries On Your Dedicated Server

In the previous lesson, you have learned about getting yourself to know whether the Memcached service on your server is installed and listening to Port 11211.

Now this lesson is on checking the presence of the required PHP libraries needed to make Memcached work for you.

You can verify the installation from SSH. Another important thing is to make sure to use the same version of PHP as the website you want to use Memcached on.

On a dedicated server having WHM/cPanel with PHP version 7.3, the following command is used with the output as shown:

[root@server[~]: ea-php73 -i | grep "memcached" /opt/cpanel/ea-php73/root/etc/php.d/memcached.ini,
memcached support => enabled

Verifying Memcached service & PHP libraries are working

From the command line, telnet to the Memcached service.

[root@server ~]# telnet localhost 11211

This output will be returned, and you will be connected to the Memcached service.

Trying ::1...
telnet: connect to address ::1: Connection refused
Connected to localhost.
Escape character is '^]'.

Enter the command stats. A full page of output will appear, but towards the middle, look for the lines STAT bytes_read and STAT bytes_written.

STAT pid 6374
STAT uptime 37567
STAT bytes_read 3733268975
STAT bytes_written 6526192728
STAT limit_maxbytes 1073741824

When you see a big amount of data is read and written, that means Memcached is working.

Entering the command stats again is going to show changes to these values.

And when you are seeing a very tiny amount of data read and written, or the values of 0, that means Memcached is not functioning good.

STAT pid 30601
STAT uptime 603941
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 1073741824

Use quit to return to a standard prompt.

Connection closed by foreign host.
[root@server ~]#

So that is how you can know that the caching is working as expected.

Know Whether Your Server’s Memcached Service Is Listening On Port 11211

If you’re not sure whether your dedicated server‘s Memcached service is listening on port 11211 i.e. it is installed and running properly, there are some easy tests you can do to make sure everything is operating fine.

Before you start, enable the administrator access on your server (in case you have not), connect via SSH then switch to the root user.

Next, in the command line, type the following command and PRESS ENTER:

telnet localhost 11211

This will report to you back that it was able to connect to the service.

[root@server[~]: telnet localhost 11211
Connected to localhost.
Escape character is '^]'.

In case, if it’s not installed properly, you will see something like this:

[root@transfer[~]: telnet localhost 11211
telnet: connect to address Connection refused

And you will not be able to connect to the service.

In the next lesson, you will learn about testing the presence of the needed PHP libraries to make Memcached work for you.

Configured Memcached PHP Libraries On Your Server, Next What?

In the previous lessons, you have learned about installing Memcached PHP Libraries and configuring Memcached Daemon on your dedicated server. Now next steps are to configure your apps and websites to use them so that you can get their real benefit.

So once you get the Memcached Daemon and PHP libraries installed on your CentOS-based dedicated server, you are required to configure your PHP application to use Memcached. In case you don’t it, Memcached is going to use your server resources without providing you any of the advantages.

Before starting, the system recommends you take a backup of your websites and then follow the changes outlined below.

WordPress users can take its benefit simply by using a plugin called W3 Total Cache Plugin. Yes, there are many other plugins as well but the system finds it best for most of its users. If in case this plugin doesn’t suit you or it is in conflict with some other plugin you are using, it that’s your case then you can choose some other plugin such as Batcache, Cachify, Memcached-Redux, etc.

In this lesson, you will learn about configuring the first and the best one i.e. W3 Total Cache. Simply start by installing-activating the plugin and then to configure, navigate to the Performance -> General Settings page.

Next, make sure the Enable tickbox is checked and Memcached is selected with the cache method for:

  • Page Cache
  • Object Cache
  • Database Cache
  • Fragment Cache

Once you do this, your website starts to use the Memcached services for imporving the performace of your website at the same time reducing the load on your dedicated server.

Configuring Object Caching System On Linux VPS & Dedicated Servers

Object caching system speeds up any dynamic database-driven website by caching data and objects in RAM. As a result, you get a faster website and a server that handles more traffic in fewer resources.

This is recommended for you especially if you have subscribed limited RAM option on your server. Even if your RAM is high, configuring it will help you reduce the resource consumption of your server.

Memcached is a free object caching system that offers you a high-performance, distributed memory object caching system.

There are 3 parts that need to be present for Memcached caching to work properly on your VPS or Dedicated Server:

  1. The background process i.e. Memcached Daemon needs to be installed on your server and configured to listen on the correct port, and start automatically at server startup
  2. The Memcached PHP libraries must be installed to allow your PHP application suchas WordPress, etc. to communicate with this object caching system
  3. Your PHP application must be configured to use Memcached

Installing & configuring Memcached on your server

Login to your VPS or Dedicated Servers. The installation is done from the command line but it works with all WHM/cPanel also Plesk

First, follow these three steps:

  1. Make sure administrator access is enabled
  2. Connect to your server with SSH
  3. Switch to the root user

Next, start with these commands:

  1. Install Memcached using YUM
    yum -y install memcached
  2. Configure Memcached to start automatically at boot time
    systemctl enable memcached
  3. Change the Memcached configuration to make the service more secure and to configure the amount of RAM to allocate:

Edit the configuration file with your favorite text editor – vim /etc/sysconfig/memcached

That’s how it will look like


It’s important to update the OPTIONS line to bind Memcached with localhost and to disable UDP traffic, protecting from certain attacks:

OPTIONS="-l -U 0"

You also need to configure CACHESIZE to the amount of RAM you’d like to use. This depends on how much total RAM the server has, but 512M to 1024M is often a good place to start:


The modified file should look something like this:

OPTIONS="-l -U 0"

Check and save the file and then use the command – systemctl restart memcached to restart Memcached. This is going to reflect your changes.

The next coming lessons will guide you on how you can test whether Memcached is working or not and also how you can set up PHP libraries and configure your website to use an object-catching system such as Memcached.