How to install and configure Redis on Almalinux

Redis (Remote Dictionary Server) as a fast in memory key-value data store is a popular object cache solution for WordPress. Main benefit of using it is a reduced workload for the database server as most of the frequent and repeated database queries are served directly from the object cache. While the object cache may not give any performance boost for small, static or mostly cached websites, it certainly is a game changer for dynamic high traffic websites such as e-commerce stores.

This guide will help you to install and properly configure newest Redis version on your Almalinux 8/9 VPS or dedicated server.

Redis Installation on AlmaLinux

Enable REMI Repository

In order to get the newest Redis version you must first enable REMI repository. Default AlmaLinux repository contains older releases, but I recommend using the newest possible one (currently Redis 8) as it will include significant performance improvements and several new user-facing features.

Use the following command according to your AlmaLinux version in order to install / enable REMI repository:

For AlmaLinux 8

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y

For AlmaLinux 9

Check for available Redis versions

By running this command you can see what Redis versions are available for installation on your server. You can run this to ensure that you will install the latest – most up to date version of Redis:

Output should look like this:

From which we see that the Redis version 8.0 from Remi’s repository is the latest one.

Installing Redis from REMI Repository

To install a newest version of Redis from the REMI repository, you must use the following command (will work on all AlmaLinux versions). Replace the X.X part with the newest version number you see in the list from running the previous command:

sudo dnf module install redis:remi-X.X -y

e.g. to install Redis 8.0, you must use a command:

However if the installation fails with an error similar to this:

Use the following commands to reset the redis module, enable and install the version you specifically want. Again this is for installing Redis 8.0. If you need a different version, modify the version number in the code to your needs:

Enable & Startup Redis after installation

As the last step to finish with default configuration, use this command to enable & startup redis as a service immediately:

sudo systemctl enable --now redis

Enable the use of Unix Sockets for REDIS

1. Instruct Redis to use Unix sockets for connection with the web server – Unix Sockets in almost every case are up to 50% faster than TCP sockets over the loopback interface.

Edit the Redis configuration file by opening it in a VI editor by using this command (according to your AlmaLinux version):

AlmaLinux 8

AlmaLinux 9

type in /unixsocket to quickly navigate to the configuration parameters you’ll need to change and press on the INSERT key to start editing the file. Uncomment the two “unixsocket” and “unixsocketperm” parameters and adjust their values to the following:

unixsocket /var/run/redis/redis.sock
unixsocketperm 770

When done press ESC key and exit the VI editor by typing :wq in the console and pressing the ENTER key.

2. Adjust the default permissions for the Redis socket file – this is necessary to solve the permissions problem for the redis socket file on a Plesk server. Without this fix you cant use Plesk in your websites via Unix sockets.

Edit the Redis service configuration file by opening it in a VI editor:

Press the INSERT key to start editing the file and add the following line under the [Service] section:

After that press ESC key, type :wq in the console and press ENTER to exit VI editor

3. Restart the Redis to apply all of the changes

Enable memory over-commit on the server

According to official Redis documentation and this article, allowing the operating system to allocate more memory for apps than physically available is almost a requirement when configuring the server for Redis. This is necessary for avoiding unnecessary system failures, optimizing Redis performance and mitigating low memory problems on the server. To do this, just type these commands in the console and reboot the server afterwards (reboot is OPTIONAL – just to check if settings have been applied permanently):

sysctl vm.overcommit_memory=1
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

To check if the settings has been applied use this command after a reboot:

Set Transparent Huge Pages to madvise

This is also a popular Redis configuration tweak to avoid any negative impact on Redis memory usage and latency. An important thing is to set Transparent Huge pages to “madvise”. You will find a lot of guides which recommends to completely disable Transparent Huge pages, but do not follow that advice since it is long outdated now.

To check the current status of Transparent Huge Pages you can use the following commands:

A safest and most reliable way to set the Transparent Huge Pages to “madvise” is by creating a system service for this operation, so first let’s start with creating a file for that. Start by executing this command:

vi /etc/systemd/system/madvise-thp.service

Then press an INSERT key and paste these contents into the file:

After this press ESC key, type in :wq in the console and press ENTER to exit the VI editor. Enable and start the newly created service by using these following commands:

After this, double check if everything is running properly by running the same cat commands I mentioned before:

How to uninstall Redis from Almalinux server

This is just for informative purposes. Uninstallation of Redis is simple – To uninstall it from your AlmaLinux server, use the following commands:

It is sufficient to use only the last command, but I added the additional two for extra safety.

Useful tools for Redis management

Redis Insight

URL: https://redis.com/redis-enterprise/redis-insight/
Redis Insight is basically a graphical user interface for managing Redis databases. You can connect it to Redis server directly or via the SSH tunnel which is a great option when you run Redis locally on your VPS / Dedicated server with no accessible ports from outside. I’ve used this tool to oversee the databases, Redis performance and sometimes locating the correct databases when I’ve lost their mapping.

FAQ about installing and configuring Redis Object Cache

Read more about Redis

Fix for Filesystem not writeable error in WordPress Redis Object Cache plugin

Leave a Comment on How to install and configure Redis on Almalinux
About the author
I'm a full-stack WordPress developer with a 10+ years of solid experience in the core web development languages, development processes / techniques, web security, Linux server management and with pretty good understanding about proper semantics, UX/UI, technical SEO, good design and basic knowledge of company leadership. On top of that - a distant 5+ years experience as a computer and electronics repair technician which often enables me to understand also how the things work at the hardware level.
Your feedback matters!…
I hope you found this article helpful. Feel free to add some comments - your feedback is very important to me, as it drives my motivation and helps me to improve the content.