Memcached can be used with dynamic web applications like WordPress, Drupal, and others to speed up applications by caching various objects from the results of API and database calls. There’s an alternative to Memcached called Redis, but Memcached is lightweight, mature, and suitable for most applications. If you’re going to be running a web application or portal and need to improve its performance, installing Memcached might be something you’ll want to implement. Also, for students and new users learning Linux, the easiest place to start learning is Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. To get started with installing Memcached on Ubuntu Linux, follow the steps below.

How to install Memcached on Ubuntu Linux

The Memcached package is included with Ubuntu default repositories and the installation process is pretty straightforward. Simply run the commands below to install it along with its support tools. Memcached tools provide several command line tools for managing the Memcached server. You’ll mostly want to install it with the Memcached server. After running the commands above, the Memcached server should be installed and ready to use. To check its status run the commands below: You should see similar lines below: The server should be running and should respond to requests. The commands below can be used to stop, start and enable Memcached.

How to configure Memcached on Ubuntu Linux

Now that the Memcached is installed, its configuration file can be found at /etc/memcached.conf The default settings in the file should be enough for most environments and applications. However, for more advanced settings, open the file and make the changes you want to apply to your environment. For example, Memcached listens on the server’s local IP address (127.0.0.1). If you want to only have it listen on a different IP, edit the lines in the file to look similar to the one below: Then replace the local server IP with the one you want to use. You can also change its default port number as well. Save the file and exit. then restart Memcached services for the changes to apply.

How to block remote access to Memcached

When the Memcached server is improperly configured, it can be used to perform a distributed denial-of-service (DDoS) attack. If you’re going to be allowing remote access you need to make sure that only trusted clients can access it remotely. You can define the remote client IP in the configuration file above. IPs that are not in the file above are automatically denied access remotely. You can also set up an Ubuntu firewall to block all remote clients except for those that are explicitly allowed on port 11211. Th To use Memcached as a caching database for your PHP application such as WordPress, Drupal, Joomla, or Magento, you need to install the php-memcached extension. Run the commands below to install the PHP Memcached PHP extension. To use Memcached with Python, install the extension below. That should do it! Conclusion: This post showed you how to install and use Memcached on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.