In this tutorial, we will show you how to install Memcached on Debian 11. For those of you who didn’t know, Memcached, the high-performance, distributed memory object caching system, is extremely useful in speeding up dynamic web applications by alleviating database load. This reduces the number of times an external data source must be read, which lowers overheads and speeds up response times. The memory caching software is a free, open-source project that anyone can use.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of Memcached on a Debian 11 (Bullseye).
Install Memcached on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following
apt commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing Memcached on Debian 11.
By default, Memcached is available on base Debian 11 repositories. Now run the following command to install it:
sudo apt install memcached libmemcached-tools
After installation, the Memcached service will start automatically. You can verify it by checking the status of the service:
sudo systemctl status memcached
Step 3. Configure Memcached.
The Memcached configuration file is
/etc/memcached.conf and we can modify the Memcached configuration by running:
sudo nano /etc/memcached.conf
In the file below, locate localhost IP 127.0.0.1. replace it with your actual server IP:
# memcached default config file # 2003 - Jay Bonci <[email protected]> # This configuration file is read by the start-memcached script provided as # part of the Debian GNU/Linux distribution. # Run memcached as a daemon. This command is implied, and is not needed for the # daemon to run. See the README.Debian that comes with this package for more # information. -d # Log memcached's output to /var/log/memcached logfile /var/log/memcached.log # Be verbose # -v # Be even more verbose (print client commands as well) # -vv # Start with a cap of 64 megs of memory. It's reasonable, and the daemon default # Note that the daemon will grow to this size, but does not start out holding this much # memory -m 256 # Default connection port is 11211 -p 11211 # Run the daemon as root. The start-memcached will default to running as root if no # -u command is present in this config file -u memcache # Specify which IP address to listen on. The default is to listen on all IP addresses # This parameter is one of the only security measures that memcached has, so make sure # it's listening on a firewalled interface. -l 127.0.0.1 # Limit the number of simultaneous incoming connections. The daemon default is 1024 # -c 1024 # Lock down all paged memory. Consult with the README and homepage before you do this # -k # Return error when memory is exhausted (rather than removing items) # -M # Maximize core file limit # -r # Use a pidfile -P /var/run/memcached/memcached.pid
Save and close the file. Then restart the Memcached process to take effect:
sudo systemctl restart memcached
Step 4. Configure Firewall.
If you have UFW installed, you need to create UFW allow rules on port 11211:
sudo ufw allow proto tcp from <your ip address> to any port 11211 sudo ufw reload
Step 5. Use Memcached.
There are many Memcached clients are available for programming languages like PHP, Python, and many more. However, to use Memcached as a caching system for your PHP applications such as WordPress, you will need to install the Memcached to extension for PHP:
sudo apt install php-memcached
Congratulations! You have successfully installed Memcached. Thanks for using this tutorial for installing the latest version of Memcached on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Memcached website.