---
title: How to Install Memcached on Ubuntu 26.04
url: https://docs.vultr.com/how-to-install-memcached-on-ubuntu-26-04
description: Install and configure the Memcached distributed memory caching system on an Ubuntu 26.04 to reduce database load and improve response times.
publish_date: 2026-04-23T14:42:19.910913Z
last_updated: 2026-04-24T13:38:43.641000Z
author: Aashish Chaurasiya
header_image: https://docs.vultr.com/public/doc-assets/2565/0705e75e-045b-4197-b93c-9792facade3d.webp
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Memcached is an open-source, high-performance distributed memory caching system that stores frequently accessed data such as database query results, API responses, and session tokens in RAM. It reduces the load on backend databases by serving repeated requests directly from memory, improving application response times.

This article explains how to install Memcached on an Ubuntu 26.04 server, configure core settings, enable SASL authentication for secure access, and test the connection using a PHP script.

## Prerequisites

Before you begin, you need to:

* Have access to an [Ubuntu 26.04 server](https://www.vultr.com/servers/ubuntu/) instance as a non-root user with sudo privileges.

## Install Memcached

The default Ubuntu 26.04 APT repositories include the Memcached package. The following steps install Memcached along with its management tools and start the service.

1. Update the APT package index.

    ```console
    $ sudo apt update
    ```

1. Install Memcached and the client utilities.

    ```console
    $ sudo apt install memcached libmemcached-tools -y
    ```

1. Confirm the installed Memcached version.

    ```console
    $ memcached --version
    ```

    Your output should be similar to the one below:

    ```
    memcached 1.6.40
    ```

1. Enable Memcached to start automatically at boot time.

    ```console
    $ sudo systemctl enable memcached
    ```

1. Start the Memcached service.

    ```console
    $ sudo systemctl start memcached
    ```

1. Verify that Memcached is active and running.

    ```console
    $ sudo systemctl status memcached
    ```

    The output should display `active (running)`, confirming that the Memcached service is operational.

## Configure Memcached

Memcached stores its configuration in `/etc/memcached.conf`. The following directives control the listening address, port, connection limits, and logging behavior.

Open the Memcached configuration file.

```console
$ sudo nano /etc/memcached.conf
```

* Find the `bind` directive and verify that Memcached listens on the localhost address only.

    ```ini
    -l 127.0.0.1
    -l ::1
    ```

* Find the port directive and verify the default connection port.

    ```ini
    -p 11211
    ```

* Uncomment the `-v` directive to enable verbose logging.

    ```ini
    -v
    ```

* Uncomment the `-c` directive to set the maximum number of simultaneous connections.

    ```ini
    -c 1024
    ```

* Add `-S` at the end of the file after `-P /var/run/memcached/memcached.pid` to enable SASL authentication.

    ```ini
    -S
    ```

Save and close the file.

## Secure Memcached with SASL Authentication

Memcached does not require authentication by default, allowing unrestricted access from any local process. The SASL (Simple Authentication and Security Layer) protocol adds username and password verification to restrict access. The following steps install the SASL package, create an authentication database, and test the secured connection.

1. Install the SASL authentication package.

    ```console
    $ sudo apt install sasl2-bin -y
    ```

1. Create the SASL configuration directory.

    ```console
    $ sudo mkdir -p /etc/sasl2
    ```

1. Create the SASL configuration file for Memcached.

    ```console
    $ sudo nano /etc/sasl2/memcached.conf
    ```

1. Add the following configuration to the file.

    ```ini
    log_level: 5
    mech_list: plain
    sasldb_path: /etc/sasl2/memcached-sasldb2
    ```

    Save and close the file.

    Within the configuration:

    * `log_level`: Sets the logging detail level. The value `5` enables detailed diagnostic logs.
    * `mech_list`: Defines the authentication mechanism. The value `plain` uses plain-text username and password.
    * `sasldb_path`: Specifies the path to the SASL user database file.

1. Create a SASL user for Memcached authentication. Replace `example_user` with your desired username.

    ```console
    $ sudo saslpasswd2 -a memcached -c -f /etc/sasl2/memcached-sasldb2 example_user
    ```

    Enter and confirm a strong password when prompted.

1. Grant the Memcached system user ownership of the SASL database file.

    ```console
    $ sudo chown memcache:memcache /etc/sasl2/memcached-sasldb2
    ```

1. Restart Memcached to activate SASL authentication.

    ```console
    $ sudo systemctl restart memcached
    ```

1. Verify that Memcached is active after the restart.

    ```console
    $ sudo systemctl status memcached
    ```

    The output should display `active (running)`, confirming that SASL authentication is enabled.

1. List all users in the SASL authentication database.

    ```console
    $ sudo sasldblistusers2 -f /etc/sasl2/memcached-sasldb2
    ```

    Your output should be similar to the one below:

    ```
    example_user@ubuntu2604: userPassword
    ```

1. Test the authenticated connection using `memcstat`. Replace `example_user@ubuntu2604` and `strong_password` with your actual credentials from the output above.

    ```console
    $ memcstat --binary --servers="127.0.0.1" --username='example_user@ubuntu2604' --password=strong_password
    ```

    A successful connection displays server statistics including the version, uptime, and connection count.

## Test Memcached with PHP

Memcached integrates with application frameworks such as PHP, Python, Ruby, and Java. The following steps install the PHP Memcached extension and verify the connection using a sample script.

1. Install PHP and the Memcached extension.

    ```console
    $ sudo apt install php php-memcached -y
    ```

1. Create a sample PHP script.

    ```console
    $ nano memcached_test.php
    ```

1. Add the following code to the file. Replace `example_user@ubuntu2604` and `strong_password` with your actual SASL credentials.

    ```php
    <?php
    $memcached = new Memcached();
    $memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
    $memcached->addServer('127.0.0.1', 11211);
    $memcached->setSaslAuthData('example_user@ubuntu2604', 'strong_password');

    $memcached->set('test_key', 'Hello World from Memcached');
    echo $memcached->get('test_key');
    ?>
    ```

    Save and close the file.

1. Run the script using the PHP CLI.

    ```console
    $ php memcached_test.php
    ```

    A successful connection returns:

    ```
    Hello World from Memcached
    ```

## Conclusion

You have installed and secured Memcached on an Ubuntu 26.04 server with SASL authentication and verified the connection using PHP. Memcached integrates with dynamic web applications as a caching layer to reduce database load and improve response times. For more information, refer to the [Memcached wiki](https://github.com/memcached/memcached/wiki).