Follow the steps below to install Redis

Step 1: Prerequisites

System running Ubuntu
Access Terminal Command line
Sudo or root privileges on local or remote machines

Step 2: Install Redis

Redis packages are available under the default apt repository for the installation of Redis on an Ubuntu VPS.

Start by updating the packages to the latest version. Run the following command:

  • sudo apt update

Install Redis using the following command.

  • sudo apt install redis-server

Once the installation is completed, you can check the version of Redis using the following command.

redis-server -v

Step 3: Configure Redis

Redis can start without a configuration file using a built-in default configuration. Aim to make Any extra parameter exchange, you can use ict configuration file: /etc/redis/redis.conf. Edit the Redis configuration file in a text editor to make changes:

  • sudo nano /etc/redis/redis.conf

Configure Memory

Update the following values ​​in the Redis configuration file. You can use its configuration file /etc/redis/redis.conf.

  • maxmemory 256mb
  • maxmemory-policy allkeys-lru

Configure supervised

For Ubuntu, we can safely select the systemd as the supervised so that Redis can interact with your supervision tree. You can use its configuration file /etc/redis/redis.conf.
Supervised systemd

Binding to localhost

By default, the Redis server doesn’t accept remote connections. You can connect to Redis only from (localhost) – the machine where Redis is running.

If you are using a single server setup where the client connecting to the database is also running on the same host, you should not enable remote access. You can use its configuration file /etc/redis/redis.conf.

  • bind ::1

Verify redis is listening on all interfaces on port 6379. Run the following command:

  • ss -an | grep 6379

Configure Password

Configuring a Redis password enables one of its two built-in security features – the auth command, which requires clients to authenticate to access the database. You can use its configuration file /etc/redis/redis.conf.

  • requirepass Bada$$320

Restart Redis for the changes to take effect.

  • sudo systemctl restart redis-server

Step 4: Install PHP Extension (Optional)

Next, if you need to use Redis with a PHP application, you need to install Redis PHP extension on your Ubuntu system. To install the Redis PHP extension, type:

  • sudo apt install php-redis

Share this post