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. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches.

In this guide, we will explain the steps in installing and configuring Memcached.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can quickly deploy your cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is recommended that you update the system to the latest packages before beginning any major installations. Issue the command below:

sudo apt-get update && sudo apt-get upgrade

Step 1: Install Memcached
Issue the command below to install Memcached from the official Debian repositories:

sudo apt install memcached libmemcached-tools

Next, check the status by issuing the commands below:

sudo systemctl status memcached

Step 2: Configuring Memcached
The core configuration file for Memcached is the /etc/memcached.conf file. By default, Memcached uses 11211 as the port number. You can also change this to any value of your choice.

By default, Memcached listens on the server's local IP address. You can change this if you want it to listen on a different IP by making changes in the conf file, as shown below:

sudo nano /etc/memcached.conf

After saving and exiting, ensure to restart Memcached for our changes to be enforced.

sudo systemctl restart memcached

Connecting to Memcached:

  • PHP: To connect Memcached to your PHP application, you need to install the php-memcached extension with the command below:

    sudo apt install php-memcached
  • Python: To connect Memcached to interact with your Python application, you can install your preferred library using pip:

    pip install pymemcache
    pip install python-memcached