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 with NGINX web server and PHP 7.3 on an Ubuntu server.

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 always 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 Ubuntu apt repositories:

sudo apt install memcached libmemcached-tools


Next, check the status by issuing the commands below:

sudo systemctl status memcached


Enable the service to start on boot by issuing the command below:

sudo systemctl enable memcached.service


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.

sudo nano /etc/memcached.conf


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

Step 3: Install and configure Nginx to Support Memcached
If you don't have Nginx and PHP 7.3 FPM installed, issue the command to install the packages and other related necessary packages:

sudo apt-get install nginx php7.3-fpm php-memcached php7.3-cli


After installation, we need to make some changes to our Nginx default configuration file:

sudo nano /etc/nginx/sites-available/default

As shown below, add index.php next to index and before index.html.


Also, add the following, as shown below:

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    #       # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.3 fpm.sock;


Restart Nginx to load the configurations:

sudo systemctl restart nginx

Step 4: Check Memcached Installation
To check our Memcached installation, we can create a PHPInfo.php to verify.

sudo nano /var/www/html/phpinfo.php

Enter the following content:

<?php phpinfo(); ?>


Next, visit your server's IP address on the browser or your domain name if you have one followed by /phpinfo.php: