How to Install Memcached on Debian 9/10

Memcached is a free and open source, high-performance, distributed memory object cache system. Memcached is simple and powerful. Its simple design facilitates rapid development, eases development, and solves many problems with large data volumes. Its API is compatible with most popular development languages.In essence, it is a concise key-value storage system.

In this tutorials, we will show you how to install and configure Memcached on Debian 9/10.


Step 1. Install Memcached

To install the Memcached packages, run the following command as root or user with sudo privileges.

apt install memcached libmemcached-tools -y

#user with sudo privileges
sudo apt intsall memcached libmemcached-tools -y

Once the installation is completed, Start the Memcached service and enable it to start at reboot with the following command:

systemctl start memcached
systemctl enable memcached

#user with sudo privileges
sudo systemctl start memcached
sudo systemctl enable memcached

To check the status of the service, run following command :

systemctl status memcached

#user with sudo privileges
sudo systemctl status memcached

The output will look something like this:

● memcached.service - memcached daemon
   Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-06-12 10:50:00 CST; 3min 41s ago
     Docs: man:memcached(1)
 Main PID: 4592 (memcached)
    Tasks: 10 (limit: 2347)
   Memory: 3.5M
   CGroup: /system.slice/memcached.service
           └─4592 /usr/bin/memcached -m 64 -p 11211 -u memcache -l -P /var/run/memcached/

6月 12 10:50:00 debian systemd[1]: Started memcached daemon.
6月 12 10:50:01 debian systemd[1]: /lib/systemd/system/memcached.service:13: PIDFile= references path below legacy directory /var/run/, updating /var/run/memc

That’s it, you have successfully installed Memcached on your Debian 10 server.

Step 2. Configure Memcached

Memcached default configuration file is located at /etc/memcached.conf. You can configure it according to your needs.

By Default, the Memcached service listens on localhost only and the default settings is enough for most applications.

if you want allow remote connections to the Memcached server, you need to configure your firewall and allow access to the Memcached UDP port 11211 only from trusted clients.

If you are using UFW, run the following command to allow assess from the remote client IP address:

sudo ufw allow from to any port 11211

If you are running plain old iptables run:

sudo iptables -I INPUT -s --dport 2112112 -j ACCEPT

However, if you want to allow remote access to your Memcached server and change the default port, edit the Memcached configuration file as shown below:

sudo vim /etc/memcached.conf

Change the following values:

# Default connection port is 11211
-p 11211

-l your-server-ip

# Limit the number of simultaneous incoming connections. The daemon default is 1024
 -c 1024

Save and close the file then restart the Memcached service to implement the changes. Restart the Memcached service for the changes to become active:

#user with sudo privileges
sudo systemctl restart memcached

Now you can connect to the Memcached server from the remote location.

Step 3. Connecting to Memcached

At this point, Memcached is installed and configured. To connect to the Memcached server you need to use a language-specific client.


sudo pip install pymemcache
sudo pip install python-memcached


pip install pymemcache


In this tutorial, you learned how to install and configure Memcached on Debian 10 server. You also learned how to enable PHP, Python support in Memcached.

For more information on this topic consult Memcached Wiki.

Leave a Reply