DebianDebian Based

How To Install Memcached on Debian 12

Install Memcached on Debian 12

In this tutorial, we will show you how to install Memcached on Debian 12. In today’s fast-paced digital world, web applications demand exceptional performance to provide users with a seamless experience. One way to achieve this is by using Memcached, a high-performance, distributed memory object caching system. By caching frequently accessed data in memory, Memcached significantly reduces the time it takes to fetch data from slower data stores like databases, resulting in faster response times and improved overall application performance.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Memcached on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Memcached.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Memcached on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing Memcached and Libraries.

Next, we’ll install Memcached and the required libraries using the following command:

sudo apt install memcached libmemcached-tools

This command will download and install Memcached along with the necessary tools for managing and monitoring it.

With Memcached installed, we need to start the service and configure it to start automatically on the system boot. Execute the following commands:

sudo systemctl start memcached
sudo systemctl enable memcached

Step 3. Configuring Memcached.

By default, Memcached uses a configuration that works for many use cases. However, you can customize its settings to suit your specific needs. To make changes, open the configuration file with your preferred text editor:

sudo nano /etc/memcached.conf

In this file, you can modify various settings, including the listening IP and port, memory allocation, and connection limits. Make the necessary changes and save the file.

To allocate a specific amount of memory to Memcached, you can adjust the -m option in the /etc/memcached.conf file. For example, to allocate 128 megabytes of memory, modify the line as follows:

-m 128

By default, Memcached listens on all available network interfaces. If you want to restrict access to specific IP addresses or interfaces, you can specify them in the configuration file:

-l 127.0.0.1

Step 4. Access Memcached from Command Line.

To confirm that Memcached is running and listening on the specified port (default is 11211), use the following command:

telnet localhost 11211

If successful, you should see a connection confirmation message.

Step 5. Using Memcached Tools.

Memcached provides several command-line tools to interact with and inspect the cache:

  • memcstat: Displays cache statistics.
memcstat --servers=localhost
  • memcdump: Dumps the contents of the cache.
memcdump --servers=localhost
  • memccat: Retrieves and displays the value for a specific key.
memccat --servers=localhost mykey

Step 6. Use Memcached with PHP.

Integrating Memcached with PHP can significantly boost the performance of web applications. To get started, you’ll need to install the PHP Memcached extension:

sudo apt install php-memcached

Then, configure your PHP application to use Memcached as a caching mechanism. Consult your application’s documentation or specific guides for detailed instructions on integrating Memcached with PHP.

Step 7. Troubleshooting.

While Memcached is a robust caching system, you may encounter occasional issues. Here are some common problems and their solutions:

  • Memcached Not Starting: Check the service status using systemctl status memcached to identify any errors in the configuration file.

  • Port or IP Issues: Verify that Memcached is listening on the correct IP and port specified in the configuration file.
  • Memory Allocation: If you encounter memory-related errors, ensure that you’ve allocated an appropriate amount of memory in the configuration.

Congratulations! You have successfully installed Memcached. Thanks for using this tutorial to install the latest version of the Memcached on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official Memcached website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button