Memcached is used to speed up dynamic database-driven websites by caching data and objects in RAM. 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.
The guide will explain how to set out installing Memcached on the Debian 10 Buster OS Distro.
Table of Contents
- Debian 10 Desktop or server.
- Up to date system packages.
- Up to date Nginx server stable or mainline.
sudo apt update && sudo apt upgrade -y
Install Memcached on Debian 10
Debian, by default, has Memcached in its repositories. To install Memcached, enter the following code below.
sudo apt install memcached libmemcached-tools
The second install option “libmemcached-tools” package, provides additional commands to bring extra interaction and execute abilities to Memcached.
Finally, make sure Memcached is live by the following.
sudo systemctl status memcached
/home/bytesboss# sudo systemctl status memcached ● memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset Active: active (running) since Thu 2021-06-17 03:11:29 EDT; 2min 20s ago Docs: man:memcached(1) Main PID: 551 (memcached) Tasks: 10 (limit: 2318) Memory: 4.8M CGroup: /system.slice/memcached.service └─551 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P / Jun 17 03:11:29 bytesboss-debian systemd: Started memcached daemon.
If, for some reason, this is not enabled, you can adjust the status by the following codes.
start memcached sudo systemctl start memcached stop memcached sudo systemctl stop memcached disable start up sudo systemctl disable memcached enable on start up sudo systemctl start memcached restart memcached sudo systemctl restart memcached reload memcached sudo systemctl reload memcached
Memcached must be listening to 127.0.0.1. You will need to check the default setting in the configuration file located at “/etc/memcached.conf“. You will notice the -l parameter set to the local interface. This prevents DDoS attacks from the network and must be checked.
sudo nano /etc/memcached.conf
Now scroll down and find the following line and check the -l parameter exists. If you have an external IP on a local network or external, you will need to modify the default IP address from 127.0.0.1 to the new IP address.
It is recommended to disable UDP. Unless you require this function to be enabled, add the following line to disable it.
Before you finish, changing the default 64MB memory allocation is recommended as this isn’t much for larger websites, and you will not see much benefit using Memcached.
You need to set this to something reasonable for your server. If you have 3 to 6 GB of RAM that is hardly used, then put it to 1GB or 2GB. This is a setting you must decide that runs best for your server. The guide’s server runs on 8GB, so we adjusted our cache to 2GB as an example only.
Now save the file CTRL+O and hit “Y”, then CTRL+X to exit and restart your Memcached instance.
sudo systemctl restart memcached
UFW Firewall Set Up
If you have set an external location, you will need to enable UFW to allow rules for that different IP address to the Memcached port 11211. Example below.
sudo ufw allow from 220.127.116.11 to any port 11211
Now you can connect to Memcached externally.
Install Memcached PHP Libraries
Memcached comes with various extensions for the programming languages, but it is primarily used for the PHP. To install the PHP library enter the following.
sudo apt install php-memcached apache2 libapache2-mod-php php php-cli php-memcached \ php-memcached
Apache HTTP Server
Apache users can execute the following code to enable Memcached on their system.
phpenmod memcached && sudo service apache2 restart
Nginx HTTP Server
Memcached for Nginx will be enabled in your PHP block by default once installed.
Install Additional Libraries
You can install Python and or Perl support by executing the following commands.
sudo apt install python3-pymemcache
sudo apt install libcache-memcached-libmemcached-perl
Comments and Conclusion
The guide has shown you how to install Memcached on your Debian 10 Buster operating system, secure it from DDOS along with installing the additional libraries. For further documentation, the project’s Github Wiki page explains further in great detail for server admins any specifications or information they require.