Hi, folks. In this post, you’ll learn how to install Memcached on Ubuntu 20.04 / Debian 10, and also we’ll quickly examine some configuration parameters.
For those who don’t know, Memcached Free & open-source, high-performance, distributed memory object caching system. Using Memcached will speed up the loading of data from your web sites and applications. If I tell you that Netflix uses it, then you can know that Memcached is a tool to take into account.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches.
So, let us start.
Install Memcached on Ubuntu 20.04 / Debian 10
Being such an important tool nowadays, Memcached is included in the official distribution repositories. This makes installation much easier but is also a fairly secure method.
So, open a terminal and run the following command:
sudo apt install memcached libmemcached-tools Reading package lists… Done Building dependency tree Reading state information… Done The following additional packages will be installed: libmemcached11 libmemcachedutil2 Suggested packages: libanyevent-perl libcache-memcached-perl libmemcached libyaml-perl The following NEW packages will be installed: libmemcached-tools libmemcached11 libmemcachedutil2 memcached 0 upgraded, 4 newly installed, 0 to remove and 87 not upgraded. Need to get 293 kB of archives. After this operation, 1064 kB of additional disk space will be used. Do you want to continue? [Y/n]
Then the installation of the program will begin.
Like other programs, Memcached is managed as a system service. So with the systemctl command, we can start it, stop it, restart it, or see its status.
To start it and make it start with the system
sudo systemctl start memcached
sudo systemctl enable memcached
And to verify their status:
sudo systemctl status memcached ● memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-08-26 22:20:43 UTC; 39s ago Docs: man:memcached(1) Main PID: 2047 (memcached) Tasks: 10 (limit: 846) Memory: 1.8M CGroup: /system.slice/memcached.service └─2047 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -P /var/run/memcached/memcached.pid Aug 26 22:20:43 osradar systemd: Started memcached daemon.
Configuring Memcached on Ubuntu 20.04 / Debian 10
The Memcached configuration file is
/etc/memcached.conf and there you can check all the options it presents.
Let’s modify it, but first let’s backup the original file:
sudo cp /etc/memcached.conf /etc/memcached.conf.bak
sudo nano /etc/memcached.conf
We can modify the port of the application, which is
11211 by default
Also, we can modify the number of incoming connections which by default is
Finally, the IP address of the server where Memcached is installed must be entered:
Save the changes and exit the editor.
To apply the changes, you can restart the service
sudo systemctl restart memcached
Enabling the PHP support
The idea is that web applications should take advantage of Memcached, so support must be enabled.
Then restart Apache.
sudo systemctl restart apache2
And to demonstrate that Memcached is enabled for use in PHP, create a phpinfo file.
sudo nano /var/www/html/phpinfo.php
And add the following:
<?php phpinfo(); ?>
Save the changes and exit the editor.
Now with your favorite web browser, open it.
When you scroll down, you will see the Memcached section.
This confirms the installation and configuration. Now your applications made in PHP will take advantage of Memcached.
In this post, you have learned the first steps with Memcached installing it and configuring it. Also enabling support for the PHP language which is the most popular language for web applications.
So share this post and join our Telegram Channel.