How to install and configure memcached on Ubuntu Linux 18.04/20.04

Memcached is a high-performance distributed memory caching system that can be used to speed up dynamic web applications by reducing the amount of time required to load data from a database. Here is an overview of the steps to install and configure Memcached on Ubuntu 18.04/20.04:

  1. Start by updating the package list:
sudo apt update
  1. Install the Memcached package:
sudo apt install memcached
  1. Start the Memcached service:
sudo systemctl start memcached
  1. Enable the Memcached service to start automatically at boot:
sudo systemctl enable memcached
  1. Configure Memcached by editing the configuration file located at /etc/memcached.conf. You can adjust the following settings:
-d : Run Memcached as a daemon.
-m : Set the amount of memory Memcached is allowed to use.
-l : Set the IP address to listen on.
-p : Set the port number to listen on.
-c : Set the maximum number of connections.
-u : Set the user to run Memcached as.
  1. Verify that Memcached is running and listening on the specified IP address and port by using the netstat command:
sudo netstat -plunt | grep memcached
  1. To test the installation, you can use the telnet command to connect to the Memcached server and set, get, and delete key-value pairs:
telnet localhost 11211
  1. To interact with Memcached, you need to install a Memcached client library for your programming language. For example, for PHP you can use the php-memcached package.
sudo apt-get install php-memcached
  1. you can use the memcached-tool command to get statistics on the Memcached server, like number of get and set commands, number of bytes used, and number of items stored.
memcached-tool localhost stats

Memcached is a powerful caching system that can be used to speed up dynamic web applications by reducing the amount of time required to load data from a database. It’s a simple installation and configuration process. It can be installed on Ubuntu 18.04/20.04, you can interact with Memcached via a Memcached client library for your programming language. Memcached also provides features like memcached-tool command which gives statistics on the Memcached server, like number of get and set commands, number of bytes used, and number of items stored.

Leave a Comment