How to Install Redis on Ubuntu 20.04

Install Redis on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure Redis on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Redis is an open-source, in-memory, data structure store with optional disk writes for persistence. It can be used as a key-value database, or as a cache and message broker. Redis features built-in transactions, replication, and support for a variety of data structures such as strings, hashes, lists, sets, and others. Redis can be made highly available with Redis Sentinel and supports automatic partitioning with Redis Cluster.

Install Redis on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Redis on the Ubuntu system.

Installing Redis with the command:

sudo apt install redis-server

Step 3. Configure Redis.

To configure Redis remote connections open the Redis configuration file with your text editor:

sudo nano /etc/redis/redis.conf

Update the following values in Redis configuration file according to your requirement. You can increase max memory limit as per available on your server:

maxmemory 512mb
maxmemory-policy allkeys-lru

Finally, restart the Redis service by running:

sudo systemctl restart redis.service

Step 4. Install PHP Extension.

You need to install Redis PHP extension on your Ubuntu system. To install the Redis PHP extension run the following commnad below:

sudo apt install php-redis

Step 5. Check Redis Connection.

Use redis-cli a tool to verify the connection between the Redis server:

$ redis-cli

127.0.0.1:6379> ping
PONG

Few more examples of redis-cli command line tool. You can find more details about redis-cli here.

That’s all you need to do to install the Redis server on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on Redis, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.