Linux Tactic

Boost Your Web App’s Performance with Memcached on Ubuntu

In today’s fast-paced digital world, it is important to ensure that your website or application has optimal performance at all times. One tool that can help is Memcached, an open-source distributed memory caching system.

In this article, we will explore how to install and configure Memcached on Ubuntu 18.04, and how to enable remote access while keeping security in mind. Installing and Configuring Memcached on Ubuntu 18.04

Before we begin, you’ll need sudo privileges to execute certain commands.

First, let’s install Memcached from the Ubuntu 18.04 repositories:


sudo apt update

sudo apt install memcached


Once you have Memcached installed, the /etc/memcached.conf file contains default configuration settings. We want to make sure it is set to listen on localhost, which is the loopback network interface and the preferred access method.

Remote access requires the use of the network IP address, which is not recommended due to security vulnerabilities. If you must allow remote access, make sure to secure your firewall by only allowing trusted clients to access Memcached.

The Memcached UDP port 11211 must also be open to the private network. For instance, we can use UFW to allow remote access only over SSH connections to the server’s private networking interface:


sudo ufw allow from to any port 22 proto tcp

sudo ufw allow from to any port 11211 proto tcp

sudo ufw enable


Once you have opened the necessary ports, restart the Memcached service to apply the changes:


sudo systemctl restart memcached


Finally, depending on your programming language, you’ll need to install the corresponding language-specific client to connect to Memcached. For PHP, you can use the php-memcached extension:


sudo apt install php-memcached


For Python, you can use either pymemcache or python-memcached:


pip install pymemcache

pip install python-memcached


Remote Access for Memcached

While remote access to Memcached can be useful, it also comes with limitations and risks. Distributed denial-of-service (DDoS) attacks, where attackers flood the server with traffic, can overload Memcached and affect performance.

To prevent such attacks, it is recommended to restrict access to Memcached through a firewall. You can use UFW to create a rule that only allows trusted clients to access Memcached over the network:


sudo ufw allow from to any port 11211 proto tcp


Note that opening the Memcached port to all IP addresses is not recommended, as it can leave your server vulnerable to unauthorized access.

Additionally, ensure that you only allow connections from the server’s private networking interface, rather than the public IP address. This way, you can secure access to Memcached from external sources while keeping them isolated from the public internet.


In this article, we have explored how to install and configure Memcached on Ubuntu 18.04, and how to enable remote access while maintaining security. Remember to always keep your servers secured and updated to prevent any vulnerabilities or exploits.

With these best practices, you can use Memcached to optimize and improve the performance of your web applications. Memcached is an open-source, high-performance, in-memory, key-value data store that is used to cache frequently accessed objects, reduce database load, and increase application performance.

It is a caching solution that stores data in memory, which makes it much faster than database queries. Memcached effectively caches database calls by storing the results in memory, instead of querying the database each time the data is accessed, which in turn results in faster application response times.

Memcached was developed by Brad Fitzpatrick in 2003 and continues to be used by thousands of websites globally, including Twitter, Wikipedia, and Facebook. Today, the project is maintained by the Memcached team, which is a group of volunteers who contribute to the codebase, documentation, and support.

The basic concept behind Memcached is to cache objects based on a key-value store. The objects can be of any type, including strings, numbers, arrays, and others.

When a client requests data, the application checks the Memcached server first. If the data is present, the application retrieves the data from the cache instead of querying the database.

This process is much faster and can help to reduce load on the database. This type of caching can be especially useful for large-scale web applications because it speeds up the delivery of frequently accessed data.

Additionally, Memcached can improve application performance by reducing the demand on the infrastructure. This can translate to faster load times, less downtime, and improved user experience.

Memcached Wiki is an additional resource for anyone interested in learning more about Memcached. The wiki covers a wide range of topics related to the use, configuration, installation, and troubleshooting of Memcached.

Additionally, it includes a comprehensive set of tutorials to help users understand how to install and use Memcached in their own projects. The wiki also includes information on how to use Memcached with various programming languages, including PHP, Python, and Ruby.

The information is easy to follow and includes step-by-step instructions on how to configure and use Memcached. Memcached can be a beneficial tool to increase the performance of your web applications by reducing database load.

It is an easy-to-use caching solution that stores frequently accessed objects in memory, thereby reducing the time it takes to retrieve data and reducing overall load on the backend infrastructure. In conclusion, Memcached is a popular, effective, and efficient key-value data caching system that can significantly improve the performance of web applications.

Its high-performance cache design can effectively reduce database load and speed up application response times. With the help of its large and supportive community, Memcached continues to evolve and improve, making it worth considering for any web application that requires high performance, scalability, and speed.

If you are interested in learning more about Memcached, the Memcached Wiki is an invaluable resource for getting started, troubleshooting, and fine-tuning your implementation. In summary, Memcached is an efficient and high-performance caching system that can help speed up web applications by storing frequently accessed data in memory.

It effectively reduces the load on the backend infrastructure by reducing database queries, which in turn results in improved application response times and better user experience. Additionally, the Memcached Wiki is an excellent resource for users who want to learn more about installation, configuration, and troubleshooting.

As such, Memcached is an essential tool and worth considering for any web application in need of fast and efficient processing.

Popular Posts