Hamsa K
Editor
6 min read | 1 month ago

How to Install Memcached on Debian 11

Install Memcached on Debian 11 bullseye

Memcached is a general-purpose distributed memory-caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source must be read. Memcached is free and open-source software, licensed under the Revised BSD license and it is a popular choice for powering real-time applications in Web, Mobile Apps, Gaming, Ad-Tech, and E-Commerce.

Also Read -> How to Install JAVA on Debian 11

Step 1: Install Memcached

First we will update repository index using apt 

sudo apt update

Memcached is available in base debian 11 repositories.

sudo apt install memcached libmemcached-tools

Now you can verify the status of service.

sudo systemctl status memcached

output:

● memcached.service - memcached daemon
     Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-10-22 05:13:55 PDT; 57s ago
       Docs: man:memcached(1)
   Main PID: 2390 (memcached)
      Tasks: 10 (limit: 1718)
     Memory: 5.4M
        CPU: 91ms
     CGroup: /system.slice/memcached.service
             └─2390 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid

By default, memcached listens on port 11211 and you can verify as below.

sudo netstat -pnltu

output:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      2390/memcached
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      443/sshd: /usr/sbin
tcp6       0      0 :::22                   :::*                    LISTEN      443/sshd: /usr/sbin

Also Read -> How to Install LAMP stack on Debian 11 

Step 2: configure memcached 

Memcached options can be configured in the /etc/memcached.conf file.Default settings are enough for most users. if you want to configure remote connection follow below steps.

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

For example, server ip address is 192.168.0.100 and your client system ipaddress is 192.168.0.150.then open conf file and replace the server ip.

sudo vi /etc/memcached.conf

Find the line that begins with -l 127.0.0.1 and replace with the server IP address 192.168.0.100 in place of 127.0.0.1

-l 192.168.0.100

save and close the file. Then restart the Memcached process to take effect.

sudo systemctl restart memcached

To allow the client machine access to the Memcached server, allow the client machine ip in firewall.

sudo ufw allow from 10.128.0.150 to any port 11211

In addition, we can specify multiple addresses separated by comma.

Next, reload the firewall for the changes

sudo ufw reload

Also Read -> How to Install php 8 on Debian 11 Bullseye

Step 3: Enable memcached for php

To use Memcached as a caching database for your PHP application,you need to install the php-memcached extension.

sudo apt install php-memcached

output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  php-common php-igbinary php-msgpack php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  php-common php-igbinary php-memcached php-msgpack php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline
0 upgraded, 10 newly installed, 0 to remove and 85 not upgraded.
Need to get 4,318 kB of archives.
After this operation, 18.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

once it is installed, restart the webserver to take effect of extension.

That's it. Now we have successfully installed memcached on Debian 11 system.

Also Read -> How to Install Visual Studio Code on Debian 11



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy