In this tutorial, we’ll show you how to install and configure Redis on Ubuntu 16.04. For those of you who don’t know, Redis is a storefront extension, BSD license, and open source. It is often referred to as a data structure server, as keys can contain strings, hashes, lists, sets, and ordered sets. Redis also supports datatypes such as navigations, publications, and subscriptions. Redis is considered more powerful than Memcache. It would be smart to bring Redis to practice and replace Memcache for a while.
This article assumes that you at least have basic Linux knowledge, know how to use the shell, and most importantly, you host your site on your own VPS. Installation is very straightforward and assumes that you are running under the root account unless you can add “sudo” to the commands to gain superuser privileges. We will walk you through the installation of Redis on an Ubuntu 16.04 LTS (Xenial Xerus) server step by step.
Installing Redis on Ubuntu 16.04 LTS
Step 1. First, make sure all system packages are up to date by running these following commands in terminal.
sudo apt-get update sudo apt-get upgrade
Step 2. Installing Redis.
Run the command below to install Redis on your machine:
apt-get install redis-server
Redis is provided by a PHP extension to work with PHP. Here we will walk through installing the PHP-Redis extension from source and using the apt repository. After the command, the Redis extension with PHP will be installed and configured:
apt-get install php-redis
Step 3. Configuring Redis Cache on Ubuntu 16.04.
To configure Redis as a cache, you need to edit the /etc/redis/redis.conf file:
To configure the maximum memory for Redis, as well as how Redis will choose what to delete when it reaches the maximum memory, add the following lines to the end of the file:
maxmemory 128mb maxmemory-policy allkeys-lru
Save and close the file, then restart the Redis service:
systemctl restart redis-server.service systemctl enable redis-server.service
Step 4. Launching and testing Redis.
We will run and check the status of Redis with the following commands:
$ systemctl start redis-server.service $ systemctl status redis-server.service redis.service - Redis In-Memory Data Store Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: enabled) Active: active (running) since Thu 2017-04-11 20:01:23 IST; 13s ago Main PID: 6238 (redis-server) Tasks: 3 Memory: 9.1M CPU: 12ms CGroup: /system.slice/redis.service └─6238 /usr/local/bin/redis-server 127.0.0.1:6379 Apr 12 08:22:21 ubuntu-16 redis-server: | `-._`-._ _.-'_.-' | Apr 12 08:22:21 ubuntu-16 redis-server: `-._ `-._`-.__.-'_.-' _.-' Apr 12 08:22:21 ubuntu-16 redis-server: `-._ `-.__.-' _.-' Apr 12 08:22:21 ubuntu-16 redis-server: `-._ _.-' Apr 12 08:22:21 ubuntu-16 redis-server: `-.__.-' Apr 12 08:22:21 ubuntu-16 redis-server: 6238:M 13 Apr 08:23:22.345 # WARNING: The T Apr 12 08:22:21 ubuntu-16 redis-server: 6238:M 13 Apr 08:23:22.345 # Server started Apr 12 08:22:21 ubuntu-16 redis-server: 6238:M 13 Apr 08:23:22.345 # WARNING overco Apr 12 08:22:21 ubuntu-16 redis-server: 6238:M 13 Apr 08:23:22.345 # WARNING you have. ... ...
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 run!" OK 127.0.0.1:6379> get test "Redis run!" 127.0.0.1:6379> exit
Congratulations! You have successfully installed Redis. Thanks for using this tutorial to install Redis on your Ubuntu 16.04 system. For further assistance or useful information, we recommend that you visit official Redis website…