Install memcached with cPanel on CentOS 7 or Cloudlinux 7

Tech
4 Comments

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 daemon:

[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 daemon.  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 ...

4 Comments. Leave new

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

    Make sure it is version 6.6.6!

    Reply
  • Will the command to start it survive a reboot of the server?

    Reply
    • It won’t.
      You could get around this by adding the EPEL repo and just installing the memcached from there. Then just edit the config file (/etc/memcached.conf usually) with your choice of settings and use ‘chkconfig memcached enable’. This would then cause it to be started after a reboot.

      Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

Menu