> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install Redis on Ubuntu, Debian and AlmaLinux

> Install Redis on Ubuntu or Debian with sudo apt install redis-server, test it with redis-cli ping, then set a password and memory limit and keep it private.

To install Redis on Ubuntu or Debian, run `sudo apt update` and `sudo apt install redis-server`. The service starts by itself and listens only on `127.0.0.1` port `6379`. Test it with `redis-cli ping`, which answers `PONG`. Then set a password and a memory limit in `/etc/redis/redis.conf` and restart with `sudo systemctl restart redis-server`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | sudo or root access |

## Before you start

* You need a user with `sudo` rights. If you are logged in as `root`, leave out `sudo`.
* Redis is an in-memory data store: it keeps data in RAM, so it is very fast. Apps use it as a cache, for sessions or for job queues (for example WordPress object caching, Laravel or Discord bots).
* Plan how much RAM Redis may use. See [check memory usage](https://help.freakhosting.com/portals/other/how-to-check-memory-usage-on-linux.md).

## How to install Redis

> [tab] Ubuntu / Debian
>
> **1. Install the package**
>
> ```bash theme={null}
> sudo apt update
> sudo apt install redis-server
> ```
>
> Ubuntu 24.04 installs Redis 7.0.
>
> **2. Check the service**
>
> ```bash theme={null}
> sudo systemctl status redis-server
> ```
>
> Look for `active (running)`. Press `q` to leave.
>
> For the newest Redis release, use the [official Redis APT repository](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/apt/):
>
> ```bash theme={null}
> sudo apt-get install lsb-release curl gpg
> curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
> sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
> echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
> sudo apt-get update
> sudo apt-get install redis
> ```

> [tab] AlmaLinux / Rocky 9
>
> Use the [official Redis RPM repository](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/rpm/). Create `/etc/yum.repos.d/redis.repo`:
>
> ```ini theme={null}
> [Redis]
> name=Redis
> baseurl=http://packages.redis.io/rpm/rockylinux9
> enabled=1
> gpgcheck=1
> ```
>
> Then import the key, install and start it:
>
> ```bash theme={null}
> curl -fsSL https://packages.redis.io/gpg > /tmp/redis.key
> sudo rpm --import /tmp/redis.key
> sudo dnf install redis
> sudo systemctl enable --now redis
> ```

> [tab] AlmaLinux / Rocky 10
>
> Version 10 ships **Valkey 8.0** instead of Redis. [Red Hat lists it](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/considerations_in_adopting_rhel_10/dynamic-programming-languages-web-servers-database-servers) as the key-value database in RHEL 10. Valkey is an open-source fork of Redis that speaks the same protocol, so Redis client libraries work with it.
>
> ```bash theme={null}
> sudo dnf install valkey
> systemctl list-unit-files 'valkey*'
> ```
>
> Enable the service name that the second command shows with `sudo systemctl enable --now <name>`. Use `valkey-cli` where this guide says `redis-cli`.

## How to check Redis works

```bash theme={null}
redis-cli ping
```

```text theme={null}
PONG
```

Store and read a test value:

```bash theme={null}
redis-cli set greeting hello
redis-cli get greeting
```

The second command prints `"hello"`.

## How to secure Redis

The [Redis security guide](https://redis.io/docs/latest/operate/oss_and_stack/management/security/) warns that it is "not a good idea to expose the Redis instance directly to the internet". On Ubuntu and Debian the config already has safe defaults:

```ini theme={null}
bind 127.0.0.1 -::1
protected-mode yes
port 6379
```

`bind` keeps Redis on the server itself. **Protected mode** makes Redis refuse outside clients when it has no password. Leave both as they are.

> [!WARNING]
>
> Do not change `bind` to `0.0.0.0` or set `protected-mode no` on a public server. An open Redis lets anyone read or delete all your data with one command. If another server needs Redis, connect over a private VPN such as [WireGuard](https://help.freakhosting.com/portals/other/how-to-set-up-a-wireguard-vpn-server.md) and allow only that address in your firewall.

### How to set a Redis password

**1. Edit the config**

```bash theme={null}
sudo nano /etc/redis/redis.conf
```

Find the commented line `# requirepass foobared` and add below it:

```ini theme={null}
requirepass Str0ng-Redis-Pass-2026
```

Use a long random password. Redis answers so fast that short passwords can be guessed quickly.

**2. Restart Redis**

```bash theme={null}
sudo systemctl restart redis-server
```

On AlmaLinux / Rocky 9 the service is `redis`.

**3. Test it**

```bash theme={null}
redis-cli ping
```

You now get `NOAUTH Authentication required.` Log in with `redis-cli --askpass`, type the password, then run `ping` again.

`requirepass` is the simple, legacy method that gives one password to every client. Redis 6 and later also support named users with their own rights through ACLs (access control lists), which Redis recommends for larger setups.

### How to limit Redis memory

Without a limit, Redis keeps growing until the server runs out of RAM. In `/etc/redis/redis.conf`, set:

```ini theme={null}
maxmemory 256mb
maxmemory-policy allkeys-lru
```

`allkeys-lru` removes the least recently used keys when the limit is reached, which suits a cache. Keep the default `noeviction` if Redis stores data you must not lose, such as queues. Restart Redis after the change.

## Frequently asked questions

### Where are Redis logs and data stored on Ubuntu?

The log is `/var/log/redis/redis-server.log` and data files are saved in `/var/lib/redis`.

### Is Redis data lost on restart?

Not by default, but you can lose changes made since the last snapshot. Redis 7.0 saves a snapshot after 3600 seconds if at least 1 key changed, after 300 seconds if 100 changed, or after 60 seconds if 10,000 changed. Set `appendonly yes` to log every write for stronger durability.

### How do I connect PHP to Redis?

Install the PHP extension, for example `sudo apt install php-redis`, then restart PHP-FPM. Point your app at `127.0.0.1` port `6379` with your password.

### Can I run Redis in Docker instead?

Yes. See [install Docker](https://help.freakhosting.com/portals/other/how-to-install-docker.md) and [use Docker Compose](https://help.freakhosting.com/portals/other/how-to-use-docker-compose.md). Do not publish port `6379` to the internet.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Install PostgreSQL](https://help.freakhosting.com/portals/other/how-to-install-postgresql.md)
>
> A database to pair with Redis.

> [card] [Install WordPress on a VPS](https://help.freakhosting.com/portals/other/how-to-install-wordpress-on-a-vps.md)
>
> Use Redis for object caching.

> [card] [Host a Discord bot](https://help.freakhosting.com/portals/other/how-to-host-a-discord-bot-on-a-vps.md)
>
> Bots often keep state in Redis.

> [card] [Check open ports](https://help.freakhosting.com/portals/other/how-to-check-open-ports-on-linux.md)
>
> Confirm 6379 is not public.

***

> [!NOTE]
>
> **Checked against the official [Redis documentation](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/apt/) and [Redis security guide](https://redis.io/docs/latest/operate/oss_and_stack/management/security/)** on 4 November 2026; install, `redis-cli`, password and memory settings tested on Ubuntu 24.04 LTS with Redis 7.0. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.