Popular blog tags

Redis is an in-memory data structure store, used as a database server, cache, and message broker. Redis is written in C programming language. It also provides a PHP module for communication between PHP script with the Redis server.

This tutorial will help you with the installation of Redis server along with PHP Redis PHP extensions on an Ubuntu 19.04, 18.04 LTS, 16.04 LTS and 14.04.

How to Configure a Redis Server on Ubuntu.

 

 

Step 1 – Open the terminal

Log in to your system with sudo privilege account using shell access, to which you need to install Redis.

ssh root


step 2. Update APT Repository Cache
(1)check the version table on your operating system
The package you are searching for is named redis-server. You can check its package info with apt show redis-server
apt-cache policy redis-server
or
apt show redis-server

you able to see the version table for your operating system version display.

Package: redis-server
Version: 5:4.0.9-1ubuntu0.2
Priority: optional
Section: universe/misc
Source: redis
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Chris Lamb <lamby@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 172 kB
Depends: lsb-base (>= 3.2-14), redis-tools (= 5:4.0.9-1ubuntu0.2)
Homepage: http://redis.io/
Download-Size: 35.4 kB
APT-Sources: http://mirrors.cloud.aliyuncs.com/ubuntu bionic-updates/universe amd64 Packages
Description: Persistent key-value database with network interface
 Redis is a key-value database in a similar vein to memcache but the dataset
 is non-volatile. Redis additionally provides native support for atomically
 manipulating and querying data structures such as lists and sets.
 .
 The dataset is stored entirely in memory and periodically flushed to disk.

(2)add PPA repository to your OS:
add-apt-repository ppa:chris-lea/redis-server


(3)In order to install Redis, you first need to update the APT repository cache of your Ubuntu. You can do that with the following command: Update the apt-get packages index files and also update existing packages to the newest versions by using the following commands:
sudo apt-get update 
sudo apt-get upgrade

 

step 2. Install Redis on Ubuntu Using the APT Command

The Redis packages are available under the default apt repository. For the installation of Redis on an Ubuntu VPS. Run below command from the terminal to install Redis on your machine:

sudo apt-get install redis-server

Press y and then hit enter to continue.

step 3. Check Redis Version

In order to check if Redis is installed properly and working correctly, you can enter the command:

redis-cli --version

The output will display the version of the utility currently installed on your machine.

output

Redis server v=5.0.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9260170b247e88b

 

step 4:check if the Redis is running.

Once the installation is completed, the Redis service will start automatically.  you can check if the Redis is running. You can do this with the following command:

sudo systemctl status redis-server

After this, you will see Active: inactive (dead) in the output of the first command in this section.You should see something like this:

● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2018-10-28 05:10:45 PDT; 2h ago
     Docs: http://redis.io/documentation,
           man:redis-server(1)
  Process: 2197 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 2201 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
 Main PID: 2226 (redis-server)
    Tasks: 4 (limit: 2319)
   CGroup: /system.slice/redis-server.service
           `-2226 /usr/bin/redis-server 0.0.0.0:6379

 

Use the following command to verify that redis is listening on all interfaces on port 6379

ss -an | grep 6379

You should see something like below. 127.0.0.1 means all IPv4 addresses on the machine.

tcp  LISTEN 0   128   127.0.0.1:6379   127.0.0.1:*
tcp  LISTEN 0   128      [::]:6379      [::]:* 

Next is to enable Redis to start on system boot. Also restart Redis service once.

sudo systemctl enable redis-server.service

 

step 5:How to Configure a Redis Server on Ubuntu

Redis can be started without a configuration file using a built-in default configuration. But to make any extra parameter changes you can use its configuration file that is: /etc/redis/redis.conf. Edit the Redis configuration file in a text editor to make changes

sudo vim /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 256mb
maxmemory-policy allkeys-lru

The above configuration tells Redis to remove any key using the LRU algorithm when the max memory of 256mb is reached. Save the configuration file and restart the Redis service:

sudo systemctl restart redis-server.service

Step 4 – Install Redis PHP Extension

Now, if you need to use Redis from PHP application, you also need to install Redis PHP extension on your Ubuntu system. Run below command to install:

sudo apt-get install php-redis

Step 5 – Test Connection to Redis Server

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

redis-cli

127.0.0.1:6379> ping
PONG
127.0.0.1:6379>

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

redis-cli info
redis-cli info stats
redis-cli info server

Install Redis on Ubuntu

How to uninstall Redis server from Ubuntu

 If you use apt-get,You can simply type below command in your terminal. This will remove the redis-server package and any other dependant packages which are no longer needed (Because of --auto-remove). And also it will delete your local/config files for redis-server (Because of purge).

sudo apt-get purge --auto-remove redis-server

 

1.How To Install and Secure Redis on Ubuntu 18.04

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04

https://linuxize.com/post/how-to-install-and-configure-redis-on-ubuntu-18-04/

2.How To Install Redis with Download, extract and compile Redis

https://redis.io/download

3.How to Install Redis on Ubuntu 18.04

https://www.hostinger.in/tutorials/how-to-install-and-setup-redis-on-ubuntu/

4.How to install Redis 3.2 on Debian 8 and Ubuntu 16

https://www.hugeserver.com/kb/install-redis-debian-ubuntu/