Share your love
Best Memcached Installation Steps on Debian 12
This tutorial intends to show you the Memcached Installation Steps on Debian 12 Bookworm. Memcached is a free and open-source memory caching software that is used to increase the speed of dynamic web apps. Memcached does this by reducing the database load. You can follow the steps below on the Orcacore website to start Memcached Installation Steps on Debian 12.
Table of Contents
Memcached Installation Steps on Debian 12
Before you start Memcached Installation Steps on Debian 12, you must have access to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.
Now follow the steps below to complete the Memcached Installation Steps on Debian 12.
Step 1 – Command To Install Memcached on Debian 12
The Memcached package is available in the default Debian 12 repository. First, run the system update with the command below:
sudo apt update && sudo apt upgrade -y
Then, use the following command to install Memcached and the required package:
sudo apt install memcached libmemcached-tools -y
You can verify your Memcached installation by using the command below:
sudo apt-cache policy memcached
Output
memcached:
Installed: 1.6.18-1
Candidate: 1.6.18-1
Version table:
*** 1.6.18-1 500
500 https://ftp.debian.org/debian bookworm/main amd64 Packages
100 /var/lib/dpkg/status
Step 2 – Verify Memcached Service Status on Debian 12
By default, Memcached should be enabled and activated during Memcached Installation Steps on Debian 12. Verify it by running the command below:
sudo systemctl status memcached
Output
● memcached.service - memcached daemon
Loaded: loaded (/lib/systemd/system/memcached.service; enabled; preset: en>
Active: active (running) since Tue 2023-09-19 08:43:37 EDT; 3min 33s ago
Docs: man:memcached(1)
Main PID: 1115 (memcached)
Tasks: 10 (limit: 4653)
Memory: 6.1M
CPU: 106ms
CGroup: /system.slice/memcached.service
...
If it is not activated, you can start and enable the Memcached service on the system boot by running the following command:
sudo systemctl enable --now memcached
Memcached is listening on port 11211. To verify that, run the below command:
ps -ef | grep memcached
Output
memcache 1115 1 0 08:43 ? 00:00:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid
root 1246 593 0 08:49 pts/0 00:00:00 grep memcached
Step 3 – Memcached Configuration on Debian 12
At this point when you have completed Memcached Installation Steps on Debian 12, you must make some configuration changes to the Memcached configuration file.
Open the file with your favorite text editor, here we use the vi editor:
sudo vi /etc/memcached.conf
Find the following line and check the “-l” parameter that exists. You can leave it as default or you must modify the default IP address from 127.0.0.1 to the internal IP address.
-l 127.0.0.1
It is recommended to disable UDP. To do this, add the following line to the file:
-U 0
Also, find the “-m” parameter and set this to something reasonable for your server:
-m 2000
When you are done, save and close the file.
To apply the changes, restart Memcached on Debian 12:
sudo systemctl restart memcached
Step 4 – Configure UFW Firewall for Memcached
If you have UFW installed, you need to allow the UFW rules on the TCP port 11211. Depending on your installation, you can use the following commands:
sudo ufw allow 11211
Singular IP network connection:
sudo ufw allow proto tcp from <ip address> to any port 11211
Cluster IP network connection with many instances:
sudo ufw allow proto tcp from <ip address>/24 to any port 11211
Note: The second UFW rule is a subnet rule. Note, make sure the internal network is secure and trustworthy before allowing it.
To apply the new rules, reload the firewall:
sudo ufw reload
Step 5 – Memcached PHP Extensions Installation
Memcached comes with various extensions for the programming languages, but it is primarily used for PHP. To install the PHP library, you can run the following command:
sudo apt install php-memcached apache2 libapache2-mod-php php php-cli php-memcached php-memcached
Note: Apache users can execute the following code to enable Memcached on their system:
# phpenmod memcached
# sudo systemctl restart apache2
Install Additional Libraries
You can install Python and or Perl support by executing the following commands.
Python support:
sudo apt install python3-pymemcache
Perl support:
sudo apt install libcache-memcached-libmemcached-perl
Step 6 – Access Memcached from Command Line
At this point of Memcached Installation Steps on Debian 12, you can use Memcached directly from the command line. To do this, use Telnet in your service:
telnet localhost 11211
Output
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Next, you can get an overview of your Memcached service by using the following command:
stats
You can refine the search by looking into the different Memcached slabs (partitions) of memory to return results.
For example, list the slabs in the instance connected:
stats slabs
For more information, you can visit the Memcached Wikis page.
Conclusion
At this point, you have learned the Memcached Installation Steps on Debian 12, install the Memcached libraries, and access it from the command line.
Hope you enjoy it. If you are looking for any help or if you have an idea, please comment for us.
You may like these articles: