In this tutorial, we will show you how to install Redis on Ubuntu 16.04 LTS. For those of you who didn’t know, Redis is an open-source, BSD licensed, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets. Redis also supports data types such as Transitions, Publish and Subscribe. ‘Redis ’ is considered more powerful than ‘Memcache’. It would be smart to bring ‘Redis’ into practice and put ‘Memcache’ down for a while.
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 a Ubuntu 16.04 LTS (Xenial Xerus) server.
- A server running one of the following operating systems: Ubuntu 160.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).
non-root sudo useror 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 16.04 LTS
Step 1. First, make sure that all your system packages are up-to-date by running the following apt-get commands in the terminal.
sudo apt-get update sudo apt-get upgrade
Step 2. Installing Redis on Ubuntu 16.04.
Installing Redis on Ubuntu is simple. Run the command below to install Redis on your machine:
apt-get 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 the apt repository. The following command will install and set up Redis extension with PHP:
apt-get install php-redis
Step 3. Configure Redis Cache on Ubuntu 16.04.
To configure Redis as a cache you need to edit the
To configure the max memory for Redis as well as how Redis will select what to remove when the max memory is reached, add the following lines at 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. Starting and Testing the Redis.
We will start and check the status of the Redis with the below 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 2016-10-20 15:07:10 IST; 17s ago Main PID: 7207 (redis-server) Tasks: 3 Memory: 6.2M CPU: 22ms CGroup: /system.slice/redis.service └─7207 /usr/local/bin/redis-server 127.0.0.1:6379 Oct 20 15:07:10 ubuntu-16 redis-server: | `-._`-._ _.-'_.-' | Oct 20 15:07:10 ubuntu-16 redis-server: `-._ `-._`-.__.-'_.-' _.-' Oct 20 15:07:10 ubuntu-16 redis-server: `-._ `-.__.-' _.-' Oct 20 15:07:10 ubuntu-16 redis-server: `-._ _.-' Oct 20 15:07:10 ubuntu-16 redis-server: `-.__.-' Oct 20 15:07:10 ubuntu-16 redis-server: 7207:M 20 Dec 16:07:10.853 # WARNING: The T Oct 20 15:07:10 ubuntu-16 redis-server: 7207:M 20 Dec 16:07:10.853 # Server started Oct 20 15:07:10 ubuntu-16 redis-server: 7207:M 20 Dec 16:07:10.853 # WARNING overco Oct 20 15:07:10 ubuntu-16 redis-server: 7207:M 20 Dec 16:07:10.853 # 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 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 on your Ubuntu 16.04 system. For additional help or useful information, we recommend you to check the official Redis website.