29 C
Texas
angeloma
Senior Writer and partner

How to install Memcached on Ubuntu 20.04 / Debian 10?

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

- Advertisement -

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[1]: Started memcached daemon.
1.- Memcached status
1.- Memcached status

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

-p [port]

Also, we can modify the number of incoming connections which by default is 1024

-c [number]

Finally, the IP address of the server where Memcached is installed must be entered:

-l your-server-ip

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.

If you already have a LAMP server installed on Ubuntu or Debian 10 and running, just install this package:

php-memcached

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.

http://your-server/phpinfo.php

When you scroll down, you will see the Memcached section.

2.- Memcached and PHP working on Ubuntu 20.04
2.- Memcached and PHP working on Ubuntu 20.04 / Debian 10

This confirms the installation and configuration. Now your applications made in PHP will take advantage of Memcached.

Conclusion

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.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article