How To Install Redis on Ubuntu 16.04

How to Install Redis on Ubuntu

Redis is an in-memory data structure store primarily used as a database and cache. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, hyper logs, bitmaps, and spatial indexes. Today, we’ll show you how to install Redis on Ubuntu 16.04.

1. Connect via SSH

Connect to your Linux server via SSH, resynchronize the package index files from their sources and install the newest versions of all packages that are currently installed on your server by using the following commands:

sudo apt-get update
sudo apt-get upgrade

Once the upgrade is completed you can move on to the next step.

2. Install Redis on Ubuntu 16.04

Installing Redis on an Ubuntu VPS is simple. Run the command below to install Redis on your machine:

sudo apt-get install redis-server

If you are planning on using Redis as an object cache for WordPress or any other PHP-based application, you need to install the following package too:

sudo apt-get install php-redis

3. Configure Redis as a cache on Ubuntu 16.04

To configure Redis as a cache you need to edit the /etc/redis/redis.conf file. We will use nano as a text editor for this purpose, but you can use any text editor of your choice.

sudo nano /etc/redis/redis.conf

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

In this example, Redis will remove any key according to the LRU algorithm when the max memory of 128mb is reached. Save and close the file, then restart the Redis service:

sudo systemctl restart redis-server.service

Next, enable Redis on system boot:

sudo systemctl enable redis-server.service

You will also need to restart your Apache or PHP-FPM service to get the php-redis extension enabled and ready to use on your server.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS

installing redis on ubuntu 16.04

4. Use Redis on Ubuntu 16.04

To use Redis as an object cache for a PHP-based application like WordPress or Magento you will need some additional configuration. For example, if you like to use Redis with WordPress you can simply install the Redis Object Cache plugin and adjust the connection parameters.

Once the plugin is enabled and the connection is established you can use the Redis command line monitor to see the real-time output. To start the Redis command line monitor you can use the following command:

redis-cli monitor

At some point, you may need to purge the Redis cache. You can do that using the Redis command line tool:

redis-cli

Once you see the Redis command prompt, run the following command to purge the cache:

flushall

The Redis documentation is a good way to start learning how Redis works as well as how to configure it for your specific application.


install redis on ubuntu 16.04

Of course, you don’t have to install Redis on Ubuntu 16.04, if you use one of our Redis VPS Hosting services, in which case you can simply ask our expert Linux admins to install and configure Redis on Ubuntu 16.04, for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to install and configure Redis on Ubuntu 16.04, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

5 thoughts on “How To Install Redis on Ubuntu 16.04”

Leave a Comment