Restart Memcached to reflect your changes.

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

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="64"
OPTIONS=""

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

OPTIONS="-l 127.0.0.1 -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:

CACHESIZE="1024"

The modified file should look something like this:

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="1024"
OPTIONS="-l 127.0.0.1 -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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.