Redis is a high-performance, open-source in-memory key-value data store commonly used as a cache, database, and message broker. For PHP-based applications like WordPress, Magento, or Laravel, Redis can significantly improve performance by reducing database load and speeding up data retrieval. Installing Redis and the PHP Redis extension on a cPanel server ensures seamless caching and data management for dynamic websites.
This guide walks you through the complete process of installing Redis and PHP Redis on a cPanel server (with root access and WHM).
Prerequisites
Before you begin, ensure the following:
You have root access to the server hosting.
Your cPanel server runs CentOS, CloudLinux, or AlmaLinux.
You have EasyApache 4 enabled (required for managing PHP extensions).
You have a working SSH client (like PuTTY or Terminal).
Step 1: Install Redis Server on cPanel
1.1 Access the Server via SSH
Log in to your cPanel server via SSH using root privileges.
ssh root@your-server-ip
1.2 Update the Server
Ensure your server is up-to-date before installing any packages.
yum update -y
1.3 Install Redis
Use the following command to install Redis via the default YUM repository:
yum install redis -y
If Redis is not available in your default repositories, you can install it from the Remi repository:
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum --enablerepo=remi install redis -y
1.4 Enable and Start Redis
Once installed, enable Redis to start on boot and start the service:
systemctl enable redis
systemctl start redis
1.5 Verify Redis is Running
Use the redis-cli command to check if Redis is active:
redis-cli ping
A successful response will return:
PONG
This confirms that the Redis server is working properly.
Step 2: Install PHP Redis Extension
The PHP Redis extension allows your PHP applications to communicate with the Redis server.
2.1 Install via WHM (EasyApache 4)
Log in to WHM (Web Host Manager).
Go to Software > EasyApache 4.
Click Customize next to your currently installed profile.
Under the PHP Extensions section, search for redis.
Select the Redis extension for each PHP version you want (e.g., PHP 7.4, 8.0).
Click Review and then Provision to apply the changes.
EasyApache will now install the PHP Redis extension.
2.2 Verify PHP Redis Installation
To confirm Redis is enabled in PHP:
php -m | grep redis
If installed correctly, it will return:
redis
Alternatively, create a phpinfo.php file in your public_html directory:
phpinfo();
?>
Access it via your browser (http://yourdomain.com/phpinfo.php) and look for the Redis section.
Step 3: Configure Redis for Optimal Performance
Redis works well out of the box, but for security and performance, you should make some adjustments.
3.1 Edit Redis Configuration File
Open the Redis config file:
nano /etc/redis.conf
Recommended changes:
bind 127.0.0.1
protected-mode yes
requirepass your_secure_password
Save and exit (CTRL + X, then Y).
3.2 Restart Redis
Apply the configuration changes:
systemctl restart redis
Step 4: Enable Redis for Applications
Once Redis and the PHP extension are installed, you can now configure your web applications to use Redis.
4.1 WordPress (Using Redis Object Cache Plugin)
Install the plugin "Redis Object Cache" from the WordPress plugin directory.
Activate the plugin.
Click "Enable Object Cache" from the Redis settings.
If Redis is running on a non-default host or port, add the following to your wp-config.php:
define('WP_REDIS_HOST', '127.0.0.1');
define('WP_REDIS_PORT', 6379);
define('WP_REDIS_PASSWORD', 'your_secure_password');
4.2 Magento
For Magento 2, you can enable Redis for cache and session storage:
php bin/magento setup:config:set --cache-backend=redis --cache-backend-redis-server=127.0.0.1 --cache-backend-redis-db=0
php bin/magento setup:config:set --session-save=redis --session-save-redis-host=127.0.0.1 --session-save-redis-log-level=3
4.3 Laravel
In your Laravel .env file:
CACHE_DRIVER=redis
SESSION_DRIVER=redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
Run the following to clear and re-cache:
php artisan config:cache
Step 5: Troubleshooting Common Redis Issues
Redis is not starting
Check the status:
systemctl status redis
Check logs:
journalctl -u redis
PHP Redis extension not loading
Ensure the Redis extension is enabled for the PHP version used by your site. You can use:
/opt/cpanel/ea-phpXX/root/usr/bin/php -m | grep redis
Replace ea-phpXX with your PHP version.
Final Thoughts
Installing Redis and PHP Redis on a cPanel server can significantly enhance the performance of dynamic web applications by reducing load times and improving response speeds. With Cyfuture Cloud's high-performance infrastructure and 24/7 support, leveraging technologies like Redis becomes easy and efficient.
Whether you're running a WordPress blog, a Magento store, or a Laravel application, integrating Redis ensures your website remains fast and scalable. Be sure to monitor usage and configure it securely to make the most of your Redis setup.