Install memcached with cPanel on CentOS 7 or Cloudlinux 7

August 23, 2017
Phil

Memcached is a “Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.”

It’s nice and easy to install and implement with cPanel, so long as you’re happy using SSH.  As a pre-requisite you should be running the latest version of cPanel (v66 at the time of writing) and all current updates should be installed. You also need to be using EasyApache 4.

You’ll then need to add the EasyApache experimental repository:

[user@server ~] sudo yum install ea4-experimental

Once this is successful you’ll need to install the memcached demon:

[user@server ~] sudo yum install ea-memcached

Now you need to install the php module for each version of php you intend to use with memcached.  The command below installs php-memcached for php7.0 – you just need to change the version for others:

[user@server ~] sudo yum install ea-php70-php-memcache ea-php70-php-memcached

Finally, you’ll need to start the memcached demon.  The number in the middle (1024 in this example) is how much memory, in megabytes, should be allocated for the cache and will obviously depend on your available memory and the usage planned:

[user@server ~] sudo memcached -d -u nobody -m 1024 127.0.0.1 -p 11211

127.0.0.1 means it is to be started on localhost and 11211 is the port (this being the default for memcached).

Many open source applications allow you to take advantage of memcached – WordPress (via plugins such as W3 TotalCache) and ownCloud both make good use of it.  You can configure them individually to use your new cache.

You can check how much work your memcached process has been doing using the stats command. First of all, telnet into the memcached service:

[user@server ~] telnet localhost 11211

Then just use the ‘stats’ command

Trying ::1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 26503
STAT uptime 2256511
STAT time 1503408119
STAT version 1.4.35
STAT libevent 2.0.21-stable
STAT pointer_size 64
STAT rusage_user 186.063186
STAT rusage_system 409.667205
STAT curr_connections 10
STAT total_connections 308621
STAT connection_structures 86 ...

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *