Skip to main content

How to Install Redis on Ubuntu 16/18/20 LTS ?

With the new transactional file locking in place, we felt it was time to get rid of APCu and replace our cache with Redis instead. APCu is kind of old, and from our understanding, it doesn’t work well with the new Laravel locking system. Redis cache is the preferred way to go.

Update APT and Install Development Tools First:  
# apt update && apt upgrade
# sudo apt install build-essential -y 
# apt-get install autoconf automake gdb git libffi-dev zlib1g-dev libssl-dev 
Install and Enable Redis Server
# sudo apt install redis-server
# sudo systemctl enable redis-server 
Change Redis configuration in file /etc/redis/redis.conf
# vi /etc/redis/redis.conf

bind ::1
maxmemory 500mb
maxmemory-policy volatile-lru
port 6379 
and after change the system configuration: (for redis use)
# echo 1 > /proc/sys/vm/overcommit_memory 
add at file /etc/sysctl.conf (for redis use)
vm.overcommit_memory = 1 [at end of the line]
and update the system configuration:
# sysctl -p 
Restart Redis:
# systemctl restart redis 
Few more examples of redis-cli command line tool
# redis-cli ping
# redis-cli info
# redis-cli info stats
# redis-cli info server 
Install PHP Extension for PHP 7.2
# apt-cache search php7.2-*
# sudo apt install php-redis 
# php --ri redis
# redis-server -v 
Performance tips for Redis Cache Server