Memcached is a high-performance free, open source, in-memory key-value data store. Usually used to speed up applications by caching various objects from the results of API calls and databases.
This article shows how to install and configure Memcache on Debian 10.
You must be logged in as a user with sudo access to be able to install packages on your Debian system.
Installing Memcache on Debian 10
The memcache package is included in the default Ubuntu 20.04 repositories. To install it, enter the following command as root or user with sudo privileges:
sudo apt update sudo apt install memcached libmemcached-tools
The libmemcached tools package provides several command line tools for interacting with the Memcached server.
After the installation is complete, the Memcached service will start automatically. You can verify it by checking the service status:
sudo systemctl status memcached
The output will look like this:
memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2020-08-14 14:22:01 CDT; 3min 40s ago Docs: man:memcached(1)
There she is. You have successfully installed Memcache on your Debian 10 server.
Memcached options can be configured in the /etc/memcached.conf file. The default configuration settings are sufficient for most users.
The memcached service listens on localhost only. If the clients connected to the server are also running on the same host, you don’t need to change the default configuration file.
If not configured properly, Memcache can be used to perform distributed denial of service (DDoS) attacks. To allow remote connections to the Memcached server you will need to configure your firewall and allow access to Memcached UDP port 11211 from trusted clients only.
The following example assumes that you are connected to the Memcached server over a private network. Server IP 192.168.100.20, and client IP address 192.168.100.30
The first step is to edit the memcache configuration and set the service to listen on the server’s private network interface:
To do this, open the memcached.conf configuration file:
sudo nano /etc/memcached.conf
Find the line starting with -l 127.0.0.1 and replace 127.0.0.1 with the server IP address 192.168.100.20.
Restart the Memcached service for the changes to take effect:
sudo systemctl restart memcached
Once the service is configured the next step is to open the memcache port on the firewall.
sudo ufw allow from 192.168.100.30 to any port 11211
You can now connect to the Memcached server from a remote location.
Connecting to Memcached
There are many memcache client implementations written for different programming languages.
To use Memcached as a caching database for your PHP applications such as WordPress, Drupal or, Magento, you need to install the php-memcached extension:
sudo apt install php-memcached
There are several Python libraries for interacting with memcache. You can install the library of your choice using pip:
pip install python-memcached
We’ve shown you how to install Memcached on Debian 10. For more information on this topic, see the Memcached Wiki.
If you have any questions or feedback feel free to comment below.