Redis is an open-source, in-memory data structure store that’s often used as a cache, message broker, and database to improve performance for dynamic web applications. This guide will show you how to install Redis on AlmaLinux 8 and 9, RockyLinux (latest versions), and CloudLinux 8 and 9 using WHM/cPanel.
Table of Contents
- Prerequisites
- Installing Redis on AlmaLinux 8 and 9 with WHM/cPanel
- Installing Redis on RockyLinux with WHM/cPanel
- Installing Redis on CloudLinux 8 and 9 with WHM/cPanel
- Installing the Redis PHP Extension
- Verifying the Installation
- Common Issues and Troubleshooting
- Conclusion
1. Prerequisites
Before starting the installation, make sure you have the following:
- WHM/cPanel installed and running.
- Root access to your server.
- PHP installed on your server.
- EasyApache 4 installed for managing PHP extensions.
2. Installing Redis on AlmaLinux 8 and 9 with WHM/cPanel
AlmaLinux is a RHEL-based distribution that is fully compatible with WHM/cPanel.
Step 1: Log in to WHM
Go to https://your-server-ip:2087/
and log in using your root credentials.
Step 2: Install Redis
First, update your system and install Redis using the following commands:
sudo dnf update -y
sudo dnf install redis -y
Step 3: Start and Enable Redis
Enable Redis to start on boot and start the service:
sudo systemctl enable redis
sudo systemctl start redis
Step 4: Confirm Redis is Running
Check the status of Redis to make sure it’s running:
sudo systemctl status redis
3. Installing Redis on RockyLinux with WHM/cPanel
The process for installing Redis on RockyLinux is similar to that on AlmaLinux.
Step 1: Log in to WHM
Access WHM by navigating to https://your-server-ip:2087/
and logging in with root access.
Step 2: Install Redis
Update your system and install Redis:
sudo dnf update -y
sudo dnf install redis -y
Step 3: Enable and Start Redis
Enable Redis to start at boot and start the service:
sudo systemctl enable redis
sudo systemctl start redis
Step 4: Verify Redis is Running
Check Redis’s status:
sudo systemctl status redis
4. Installing Redis on CloudLinux 8 and 9 with WHM/cPanel
CloudLinux includes advanced features such as CageFS and ALT-PHP, which are important when installing Redis in shared hosting environments.
Step 1: Log in to WHM
Navigate to https://your-server-ip:2087/
and log in with root credentials.
Step 2: Install Redis
First, update your system and install Redis:
sudo yum update -y
sudo yum install redis -y
Step 3: Enable and Start Redis
Enable Redis to start on boot and start the service:
sudo systemctl enable redis
sudo systemctl start redis
Step 4: Install Redis for ALT-PHP
If you’re using ALT-PHP, you’ll need to install the Redis PHP extension for each version of PHP:
for version in alt-php{70,71,72,73,74,80,81}; do
yum install $version-pecl-redis -y
done
Step 5: Update CageFS
After installing Redis for ALT-PHP, update the CageFS skeleton:
cagefsctl --force-update
5. Installing the Redis PHP Extension
To integrate Redis with your PHP environment, you need to install the Redis PHP extension via EasyApache 4.
Step 1: Open EasyApache 4 in WHM
In your WHM dashboard, search for EasyApache 4 in the search bar and open it.
Step 2: Customize Your PHP Installation
Click on Customize next to your profile. Under PHP Extensions, search for Redis.
Step 3: Install the Redis Extension
Select the PHP versions you are using and enable the Redis extension by checking the box.
Step 4: Provision and Restart Apache
Click Review and then Provision to apply the changes. Once complete, restart Apache:
sudo systemctl restart httpd
6. Verifying the Installation
To verify that Redis is working with PHP, follow these steps:
Step 1: Create a PHP Info File
Create a PHP file to check if Redis is installed:
echo "<?php phpinfo();" | sudo tee /usr/local/apache/htdocs/info.php
Step 2: Open the PHP Info Page
Open your browser and navigate to http://your-server-ip/info.php
. Look for Redis in the PHP information.
Step 3: Remove the PHP Info File
For security reasons, remove the info.php file once you’ve confirmed Redis is installed:
sudo rm /usr/local/apache/htdocs/info.php
7. Common Issues and Troubleshooting
Issue 1: Redis Not Appearing in PHP Info
Solution:
- Ensure the Redis extension is enabled for the correct PHP version in EasyApache 4.
- Restart Apache after provisioning the Redis extension.
Issue 2: Redis Fails to Start
Solution:
- Use
journalctl -xe
to diagnose potential issues with Redis failing to start. - Ensure the Redis port (default 6379) is available and not blocked by a firewall.
Issue 3: Redis Not Working with ALT-PHP
Solution:
- Install the Redis PHP extension for all ALT-PHP versions using the command in the CloudLinux section.
- Run
cagefsctl --force-update
to ensure new extensions are properly applied in CageFS.
8. Conclusion
Installing Redis on AlmaLinux, RockyLinux, and CloudLinux using WHM/cPanel is straightforward. Redis is an essential tool for optimizing the performance of dynamic web applications by reducing database load and improving speed. EasyApache 4 makes it simple to set up Redis with PHP. Make sure to verify the installation and use the troubleshooting steps if any issues arise.