Redis Server and Php Extension Installation on Ubuntu 22.04 LTS

Redis is an open-source, in-memory data storage tool used by millions of developers as a cache, vector database, document database, streaming engine, and message broker. If you want to install Redis on your system, you are in the right place. In this article, we will explain the easiest way to install Redis on your system.

Where is Redis used ?

Thanks to its high performance, Redis is used to save data in cache (RAM). You can also use Redis to cache high-traffic pages. Since once cached data is no longer read from the disk but from the RAM, the reading speed performance increases at an admirable rate. Redis database is generally used in the following situations.

  • In cases where your application changes dynamically very frequently, such as user roles and permissions and session information, and you do not want the user to constantly go to the database.
  • As a message distributor in online messaging systems such as Chat.
  • In statistical operations such as site traffic data collection.
  • To keep statistics of failed logins.
  • To keep the temporary code in cache after users are sent codes such as forgot password or reset code.
  • To impose a security measure such as a rate limit on your API application.
  • To create a sorted list of scores in a game project using the Redis Sorted Set data structure.
  • or even as a message broker like RabbitMQ.


Before installing Redis server on Ubuntu, use the following command to update the system and all dependencies.

sudo apt update

Redis Server package data is available in Linux’s apt (Advanced Package Tool) repository and Redis can be installed on Ubuntu using the following command.

sudo apt install redis-server

After Redis installation, check the status of the service and whether it is running or not. So run the command below.

sudo service redis status
redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-02-24 14:24:02 +03; 4h 19min ago
   Main PID: 963 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4554)
     Memory: 5.6M
        CPU: 13.571s
     CGroup: /system.slice/redis-server.service
             └─963 "/usr/bin/redis-server" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">

If you want the redis server to start automatically every time you restart your system, run the command below.

sudo systemctl enable redis-server

Local Environment Configuration

When you use Redis as a cache, you need to change some parameters in the default configuration file located in /etc/redis/redis.conf. Since there will be no need for operations such as setting a password in the Redis Configuration for your local server, it will be sufficient to make the following settings. Run the following command to edit in the terminal.

vim /etc/redis/redis.conf

The following settings will allow you to access Redis from a remote computer without any password.

protected-mode no

After the changes made, you will need to restart the Redis server.

service redis-server restart

Production Environment Configuration

For security reasons in the production environment, we recommend that you close the Redis server to the outside or use it with a VPN. And you should definitely set a password. The following ip address configuration only allows access to the Redis server from the local server and denies remote access requests.

bind ::1
protected-mode yes

Find the Require pass line and write your password in the value opposite it.

requirepass write_your_secure_password

PHP Redis Extension Installation

If you want to use the Redis server with PHP-based applications, you must install the PHP Redis module using the command below. Before installing the module, PHP must be installed on the system.

sudo apt install php-redis

Run the command below to activate Redis module PHP.

sudo phpenmod redis

If you want to disable the module, try the following command.

sudo phpdismod redis

Multiple Php Versions

If you have multiple PHP versions on your system and need to activate the PHP Redis extension for another version, follow the steps below. In this example; We assume that you have Redis installed for PHP 8.1 on your system and that you need to activate Redis for PHP 8.2.

sudo apt-get install php8.2-redis
phpenmod -v 8.2 redis

Test Redis Connection

You can test whether the Redis server is working properly using the Redis CLI, run the command below.

redis-cli ping

Some Useful Redis-Cli Commands

redis-cli info stats
redis-cli info server

You can use the following command to list all registered data keys on the Redis server.

redis-cli --scan --pattern '*'

The following command will quickly solve your problem to delete/clear all saved cache on the server.


Redis Auth

It is not possible to run redis commands in a production environment without authentication. For this you need to use the auth command.

auth your-password

Redis Desktop Applications

Finally, let’s talk about desktop applications with a visual interface that will allow you to easily manage your Redis database.

If you are using Windows, you can connect to the redis server locally or remotely with the application, which has an easy interface, and you can view the data you have created in the database in different formats with this free application.

You can download the application from the Microsoft store for Windows operating systems from the link below.


RedisInsight Developed by Redis; A redis interface with advanced features that can also run on operating systems such as Windows, macOS (including M1), Linux.

You can download the RedisInsight application from the following link.


Redis Server is an open source software used mainly for data storage and object caching. As we mentioned above, Redis Server can be easily installed on Ubuntu/Linux operating systems. In this article, you have installed and configured Redis, verified whether your Redis installation is working properly, and completed the Redis installation steps safely for the production environment.

Note that once someone logs into your server, it is very easy to bypass the Redis-specific security features we have implemented. Therefore, the most important security measure on your Redis server in the production environment is access to the server through a firewall or a private network such as a VPN.

Leave a comment

Your email address will not be published. Required fields are marked *