How to Install Redis on Ubuntu 22.04 LTS

In this article we are going to cover How to Install Redis on Ubuntu 22.04 LTS,Configure Redis on Ubuntu 22.04 LTS,Connect to Redis Server using CLI,Managing the Redis Service on Ubuntu.

Prerequisites

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

Step #1:Install Redis on Ubuntu 22.04 LTS

Redis packages are available under the default apt repository to Install Redis on Ubuntu 22.04 LTS.

Run the following command:

sudo apt update

Install Redis using the following command.

sudo apt install redis-server

Check the version of Redis using the following command.

redis-server -v

Step #2:Configure Redis on Ubuntu 22.04 LTS

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 supervised in Redis

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.

How to Install Redis on Ubuntu 22.04 LTS 1

Binding to localhost in Redis

By default, the Redis server doesn’t accept remote connections. You can connect to Redis only from 127.0.0.1 (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 127.0.0.1 ::1

How to Install Redis on Ubuntu 22.04 LTS 2

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

ss -an | grep 6379

Output:

ubuntu@ip-172-31-37-12:~$ ss -an | grep 6379
tcp   LISTEN 0      511                                     127.0.0.1:6379                0.0.0.0:*
tcp   LISTEN 0      511                                         [::1]:6379                   [::]:*
ubuntu@ip-172-31-37-12:~$

Configure Password in Redis Server

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.

How to Install Redis on Ubuntu 22.04 LTS 3

Restart Redis sever:

sudo systemctl restart redis-server

Step #3:Install PHP Extension (Optional) for Redis

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

The installer will automatically enable the redis extension for all the pre-installed PHP versions. If your installer new PHP version after this, you can use the below command to help the redis module. Run the following command:

sudo phpenmod -v <Any PHP Version> -s ALL redis

Step #4:Connect to Redis Server using CLI

Run the following command:

redis-cli

Output:

127.0.0.1:6379> auth devopshint
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

Step #5:Managing the Redis Service

Now that you have your service up and running, let’s go over basic management commands.

To stop your service, run this command:

sudo systemctl stop redis-server

To start your service, run this command:

sudo systemctl start redis-server

To disable your service, run this command:

sudo systemctl disable redis-server

To enable your service, run this command:

sudo systemctl enable redis-server

To status your service, run this command:

sudo systemctl status redis-server

Output:

ubuntu@ip-172-31-37-12:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-01-19 08:37:03 UTC; 2min 47s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 9917 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 1143)
     Memory: 2.6M
        CPU: 307ms
     CGroup: /system.slice/redis-server.service
             └─9917 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

Jan 19 08:37:02 ip-172-31-37-12 systemd[1]: Starting Advanced key-value store...
Jan 19 08:37:03 ip-172-31-37-12 systemd[1]: Started Advanced key-value store...

Conclusion:

In this article we have covered How to Install Redis on Ubuntu 22.04 LTS,Configure Redis on Ubuntu 22.04 LTS,Connect to Redis Server using CLI,Managing the Redis Service on Ubuntu.

Related Articles:

How to Install Redis on Ubuntu 18.04 and 16.04 LTS

Reference:

Install Redis on Linux official page

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap