In this tutorial, we will show you how to install Redis on Ubuntu 18.04 LTS. For those of you who didn’t know, Redis is an open-source, in-memory data structure store that can be used as a database, cache, and message broker. It is known for its high performance, scalability, and versatility, making it a popular choice for various applications, including web applications, real-time analytics, and caching solutions.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Redis on an Ubuntu 18.04 (bionic beaver).
Prerequisites
- A server running one of the following operating systems: Ubuntu 18.04 (bionic beaver).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Redis on Ubuntu 18.04 LTS Bionic Beaver
Step 1. It is always a good practice to keep your system packages up-to-date before installing any new software. This helps to ensure compatibility and security. Open your terminal and run the following commands:
sudo apt update sudo apt upgrade
Step 2. Installing Redis on Ubuntu.
With your system packages updated, you can now proceed to install Redis. In your terminal, run the following command:
sudo apt install redis-server
Redis provides a PHP extension to work with PHP. Here we will cover the installation of Redis Extension of PHP from source compilation and using an apt repository. The following command will install and set up the Redis extension with PHP:
sudo apt install php-redis
Once the installation is complete, you can verify the status of the Redis server by running:
sudo systemctl status redis-server
Step 3. Configure Redis Cache.
Redis comes with a default configuration file located at /etc/redis/redis.conf
. While the default settings are suitable for most use cases, you may want to customize the configuration to suit your specific needs.
To configure Redis as a cache you need to edit the /etc/redis/redis.conf
file:
sudo nano /etc/redis/redis.conf
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 0.0.0.0 ::1
Restart the Redis service for changes to take effect:
sudo systemctl restart redis-server
We will now test the Redis instance with some commands:
$ redis-cli 127.0.0.1:6379> ping PONG 127.0.0.1:6379> set test "Redis Working!" OK 127.0.0.1:6379> get test "Redis Working!" 127.0.0.1:6379> exit
Congratulations! You have successfully installed Redis. Thanks for using this tutorial for installing Redis in Ubuntu 18.04 (bionic beaver) system. For additional help or useful information, we recommend you to check the official Redis website.