Memcached is an open-source distributed memory object caching system developed by Danga Interactive. Its general purpose is to speed up dynamic web applications by reducing the database load and it is currently widely used by many web applications.
In this article, we will explain how to install memcached on Ubuntu 20.04 LTS, but the procedure is also valid for most distributions based on Debian.
Installing memcached
First, as we always recommend, update the repositories and packages:
# apt update && apt upgrade
Once the update is complete, you can install memcached directly with the client library and tools using the system package installer:
# apt install memcached libmemcached-tools -y
Once installed, it will automatically create and start a service. You can check its status by running:
# systemctl status memcached
You should see the following result (active):
● memcached.service - memcached daemon
Loaded: loaded (/lib/systemd/system/memcached.service; enabled; vendor pre>
Active: active (running) since Sun 2022-04-10 19:48:33 CEST; 2min 17s ago
Docs: man:memcached(1)
Main PID: 3312 (memcached)
Tasks: 10 (limit: 2274)
Memory: 1.4M
CGroup: /system.slice/memcached.service
└─3312 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 >
Apr 10 19:48:33 memcached systemd[1]: Started memcached daemon.
Now you still need to connect your application. There are many memcached client implementations written for different programming languages, and below we will explain how to install the two most common ones.
PHP extension
To use Memcached for a PHP application such as WordPress, Drupal, Joomla or Magento, you need to install the php-memcached extension:
# apt install php-memcached
The package installer installs the extension for the default version. If you want to install it for a specific version, specify the particular package; you must have added the PHP repository beforehand:
# add-apt-repository -y ppa:ondrej/php
For example, to install the extension for PHP version 7.4:
# apt install php7.4-memcached
Additionally, if you need to enable execution via CLI, add the following to the PHP configuration (php.ini):
apc.enable_cli = 1
Once the extension is installed, you will be able to connect your application, and with the option mentioned above enabled, you will also be able to run commands via CLI using PHP.
Python libraries
There are several Python libraries available for interacting with Memcached. You can install your preferred library using the Python package installer (pip). The following list includes some of them:
# pip install pymemcache
# pip install python-memcached
For more information about using memcached, you can consult the Wiki on the official Github account.
We hope this article has helped you🙂. Remember, if you have questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We are here for whatever you need!