Memcached is a free and open-source, high-performance, distributed memory object caching system which store data in-memory by key-value pair. Memcached is basically used to store cache objects which can be either API or data from the database.
This article will guide you on how to install Memcache on ubuntu 20.04 and 18.04.
Table of Contents
Installing Memcache on Ubuntu
By default, Memcache is available in the ubuntu repository. All you have to do is to update the Ubuntu repository. Enter the below command to update.
sudo apt-get update
Once your repository is updated. Enter the following command to install Memcache in your Ubuntu machine.
sudo apt install memcached libmemcached-tools
memcached command will install the Memcache.
libmemcached-tools will provide you the command-line utility for the Memcache management.
Once the installation is completed. The Memcache will start automatically. To ensure Memcache is installed properly, Enter the following command to check the status of Memcached.
sudo systemctl status memcached
The above command's output will look like this
● memcached.service - memcached daemon Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-07-12 18:49:40 IST; 27s ago
If you see the above message. you have successfully installed Memcache in your system.
All the Memcached configuration is available in the
/etc/memcached.conf configuration file. By default, Memcached is set to listen on the localhost(127.0.0.1).
Setting up Remote Access
Note: If you are using Memcache on the same client-server then you shouldn't allow remote access.
Let's assume the Memcache server's ip address is xx.xx.xx.12 and the client's server ip address is xx.xx.xx.52.
The first thing we have to do is to edit the Memcache configuration file and replace the localhost IP to your Memcache IP. Enter the following to edit the configuration file.
# /etc/memcached.conf sudo vi /etc/memcached.conf
Next, find the line that starts with
and replace the
127.0.0.1 with xx.xx.xx.12. Once you are done save it and close.
Next, Restart the Memcache with the below command.
sudo service memcached restart
Now open the Memcache port 11211 in the firewall with the following command.
sudo ufw allow from 192.168.100.30 to any port 11211
Now the installation and configuration are done. There are many language that Memcached can be implement with.
To use Memcached with PHP it will require
php-memcached extension. To install the extension enter the following command.
sudo apt-get install php-memcached
To use Memcache with Python it will required the
pymemcache. Enter the following command to install the package
pip install pymemcache
pip install python-memcached
In this article we learn how to install, configure and use the Memcache. For more details of Memcahe you can refer the following Memcache article.