LinuxTutorialsUbuntu

How To Install Redis on Ubuntu 14.04

Install Redis on Ubuntu 14.04

In this tutorial, we will show you how to install Redis on Ubuntu 14.04. For those of you who didn’t know, Redis, an open-source in-memory data structure store, has gained immense popularity as a high-performance caching solution and a versatile database. Its ability to handle diverse data types, such as strings, hashes, lists, sets, and sorted sets, makes it an essential tool for developers and system administrators alike. Redis offers lightning-fast read-and-write operations, making it ideal for real-time applications, session management, and message queues.

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. I will show you the step-by-step installation of Redis on Ubuntu 14.04.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 14.04, and any other Debian-based distribution.
  • 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 the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Redis on Ubuntu 14.04

Step 1. To ensure a smooth installation process and maintain system stability, it is crucial to update your Ubuntu server’s package lists and upgrade existing packages to their latest versions. Open your terminal and execute the following commands:

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing Build Dependencies.

Redis is typically compiled from sources to ensure optimal performance and compatibility with your system. To compile Redis, you’ll need to install a few build dependencies. Run the following command to install the required packages:

sudo apt-get install build-essential tcl8.5

Step 2. Install Redis on Ubuntu 14.04.

Visit the official Redis download page at http://redis.io/download to find the latest stable version of Redis. At the time of writing, the latest stable version is 6.2.6. Download the Redis source tarball using the wget command:

wget http://download.redis.io/releases/redis-6.2.6.tar.gz

Once the download is complete, extract the Redis source code from the tarball using the tar command:

tar xzf redis-6.2.6.tar.gz

After extraction, navigate into the Redis source directory:

cd redis-6.2.6

Now that you’re inside the Redis source directory, it’s time to compile Redis. Follow these steps:

cd deps

Compile the Redis dependencies:

sudo make hiredis jemalloc linenoise lua

Return to the Redis source directory:

cd ..

Compile Redis:

sudo make

Run the Redis tests to verify the build:

sudo make test

Install Redis system-wide:

sudo make install

Step 3. Configure Redis.

Redis comes with a default configuration file named redis.conf. To customize Redis according to your needs, you can modify this file. The default configuration file is located at /etc/redis/redis.conf. Open the configuration file using your preferred text editor:

sudo nano /etc/redis/redis.conf

Here are a few important configuration options you may want to tweak:

  • supervised systemd: This option enables Redis to run as a systemd service.
  • dir /var/lib/redis: Specify the directory where Redis will store its data.
  • bind 127.0.0.1: By default, Redis listens on all network interfaces. To restrict access to localhost only, uncomment this line.

Step 4. Set Up Redis to Run as a Service

To ensure that Redis starts automatically on system boot and can be easily managed, set it up as a systemd service. Follow these steps:

sudo nano /etc/systemd/system/redis.service

Paste the following content into the file:

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

Save the file and exit the text editor, then enable the Redis service to start on boot:

sudo systemctl enable redis
sudo systemctl start redis

To verify that Redis is running correctly, use the following command:

sudo systemctl status redis

To further test the Redis installation, connect to the Redis server using the redis-cli command-line interface:

redis-cli

Once connected, run a simple PING command to test the connectivity:

127.0.0.1:6379> PING
PONG

Step 5. Install Redis PHP extension.

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 apt the repository. The following command will install and set up the Redis extension with PHP:

sudo apt-get -y install php5-redis

Congratulations! You have successfully installed Redis. Thanks for using this tutorial for installing the Redis server on Ubuntu 14.04 system. For additional help or useful information, we recommend you to check the official Redis website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button