How to Install and Configure Memcached

Memcached is a free, open-source memory object caching system that accelerates dynamic web applications by caching data in memory. It is designed for PHP-based web applications such as WordPress, Joomla, Drupal, and Python-based applications. You can improve database performance by temporarily storing information in memory. This reduces the number of direct queries to the database.

Install Memcached

The Memcached package is included in the Debian default repository by default. You can install it by running the following command:
apt install memcached libmemcached-tools -y

Manage Memcached Service

The memcached service is managed by systemd. To start the Memcached service,we run the following command:
systemctl start memcached
To enable the Memcached service to start :
systemctl enable memcached
And to check the status of the Memcached service using the following command:
systemctl status memcached
By default, Memcached listens on port 11211.

Configure Memcached

Memcached default configuration file is located at /etc/memcached.conf. We can edit it to change the default settings as per your requirements.
nano /etc/memcached.conf
Change the following lines as per your requirement:
## Specify the IP address on which Memcached listens on. 

## Disable the UDP

-U 0

## Define the memory to store the cache.

-m 1000

Install Memcached PHP Extensions

If you are using a PHP-based application, then you will need to install some PHP extensions to enable Memcached. You can install all of them by running the following command:

apt install apache2 php-memcached libapache2-mod-php php php-cli php-memcached php-memcached -y

Once all the packages are installed then enable the PHP Memcached module with the following command:

phpenmod memcached

Now, we must only restart the Apache service to apply the changes:

service apache2 restart

Add Python and Perl Memcached Support

If you are using Python-based web applications, you must install the Python Memcached library on your server.

apt install python3-pymemcache -y


If you are using Perl-based web applications then you will need to install the Perl Memcached library on your server.

apt install libcache-memcached-libmemcached-perl -y


Scroll to Top