How to install, configure and use Redis on Ubuntu 16.04

Redis is an in-memory data storage structure, and is mainly used as a database and cache memory. In this tutorial, we are going to show you how to install, configure and use Redis on a Linux VPS that will run Ubuntu 16.04 as the operating system.

Connect to Linux server using SSH, update OS packages to the latest versions:

sudo apt-get update
sudo apt-get upgrade

After the update is complete, you can proceed to the next step.

Install Redis on Ubuntu 16.04

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

sudo apt-get install redis-server

If you plan to use Redis as an object cache for WordPress or any other PHP 7 application, you need to install the following package too:

sudo apt-get install php-redis

Configuring Redis as Cache on Ubuntu 16.04

To configure Redis as a cache, you need to edit the file /etc/redis/redis.conf… 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 maximum memory for Redis, and also Redis will choose what is best to remove when the maximum memory is reached, add the following lines to 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 maximum memory of 128mb is full. Save and close the file, then restart the Redis service:

sudo systemctl restart redis-server.service

Then enable Redis at system boot:

sudo systemctl enable redis-server.service

You will also need to restart Apache or the PHP-FPM service to run the PHP-Redis extension and it will be ready to use on your server.

Use Redis on Ubuntu 16.04

To use Redis as an object cache for PHP applications like WordPress or Magento, you need some additional configuration. For example, if you want to use Redis with WordPress you can simply install the Redis Cache Object plugin and configure your connection parameters, or read our guide.

After the plugin is enabled and the connection is established, you can use the Redis command line monitor to see the result in real time. To start the Redis command line monitor, you can use the following command:

redis-cli monitor

At some point, you may need to clear the Redis cache. You can do this with the Redis command line tool:


After you see the Redis command line, run the following command to clear the cache:


Redis Documentation this is a good way to get started learning how Redis works and how to configure it for a specific application.