
Redis Object Cache Setup Guide for LiteSpeed Cache in WHM/cPanel
Redis Object Cache Setup Guide for LiteSpeed Cache in cPanel
By Thomas McKee |
Meta Title: Redis Object Cache Setup for LiteSpeed Cache in cPanel
Meta Description: Learn how to configure Redis Object Cache with LiteSpeed Cache in cPanel for blazing-fast WordPress performance, improved SEO, and reliable caching.
TL;DR:
Boost your WordPress site’s speed and SEO with Redis Object Cache in LiteSpeed Cache. This guide walks you through setting up Redis at /var/run/redis/redis.sock, creating cPanel users, assigning them to the redis group, and configuring LiteSpeed Cache for optimal performance on AlmaLinux 8.10 with cPanel/WHM.
Why Redis with LiteSpeed Cache Matters
LiteSpeed Cache is a powerful plugin that leverages server-level caching to supercharge WordPress performance. When paired with Redis object caching, it reduces database load, speeds up dynamic content delivery, and boosts SEO by improving page load times and Google PageSpeed scores.
Prerequisites
- Redis installed and running:
yum install redis; systemctl enable redis; systemctl start redis /etc/redis.confconfigured with:
Restart Redis:bind 127.0.0.1 port 6379 unixsocket /var/run/redis/redis.sock unixsocketperm 770systemctl restart redis- LiteSpeed Web Server installed in cPanel/WHM.
- PHP Redis extension installed:
Adjust for your PHP version (e.g.,yum install ea-php84-php-redis; systemctl restart lswsea-php82-php-redis). - Avoid conflicting plugins like Redis Object Cache:
wp plugin deactivate redis-object-cache --path=/home/newuser/public_html
Creating a New cPanel User
Steps:
- Log in to WHM (
https://yourserver.com:2087). - Go to Account Functions > Create a New Account.
- Fill in:
- Domain:
yourdomain.com - Username:
newuser(e.g.,tangobooking) - Password: Generate or set a strong password.
- Email: Your email address.
- Package: Select a hosting package.
- Settings: Enable cPanel access, set resource limits.
- Domain:
- Click Create.
- Verify the user is in the
redisgroup (via hook/usr/local/cpanel/hooks/postwwwacct/10-add-to-redis-group):
Ifgroups newuserredisis missing, add manually asroot:usermod -aG redis newuser
Assigning Users to Redis Group
Steps for Existing or Multiple Users:
- Add a specific user:
usermod -aG redis newuser - Add all cPanel users:
for user in /home/*; do usermod -aG redis $(basename $user); done - Verify:
for user in /home/*; do echo "$(basename $user): $(groups $(basename $user))"; done - Restart the web server:
systemctl restart lsws # Or httpd
Pro Tip: The cPanel hook ensures new accounts are automatically added to the redis group, making this scalable for all sites.
Configuring Redis Object Cache
For optimal performance, use the Redis Unix socket at /var/run/redis/redis.sock, which is faster than TCP connections.
Settings:
- Log in to cPanel (
https://yourdomain.com/cpanel). - Install WordPress (via cPanel > WordPress Toolkit or manually).
- Install LiteSpeed Cache in WordPress admin (
https://yourdomain.com/wp-admin):- Go to Plugins > Add New, search for "LiteSpeed Cache", install, and activate.
- Go to LiteSpeed Cache > Cache > Object.
- Set:
- Object Cache: ON
- Method: Redis
- Host:
/var/run/redis/redis.sock - Port:
0 - Redis Database ID:
0(or unique for multisite) - Username and Password: Leave blank unless required.
- Click Save Changes and verify Connection Test: Passed.
- If it fails, try TCP:
- Host:
127.0.0.1 - Port:
6379
- Host:
- Test functionality:
- Purge caches (LiteSpeed Cache > Toolbox > Purge All).
- Visit
https://yourdomain.comand check HTML source for Object Cache stats (e.g.,<!-- Object Cache [total] 4643 [hit] 386 [miss] 81 -->).
Troubleshooting
- Connection Test Failed:
- Test socket as
newuser:
Expected:redis-cli -s /var/run/redis/redis.sock pingPONG - Test PHP connection:
Accessecho '<?php $redis = new Redis(); $redis->connect("/var/run/redis/redis.sock"); $result = $redis->ping(); var_dump($result); ?>' > /home/newuser/public_html/redis_test_sock.php chown newuser:newuser /home/newuser/public_html/redis_test_sock.php chmod 644 /home/newuser/public_html/redis_test_sock.phphttps://yourdomain.com/redis_test_sock.php. Expected:string(5) "+PONG"orbool(true). - Test TCP:
redis-cli -h 127.0.0.1 -p 6379 ping - Check socket permissions as
root:ls -l /var/run/redis/redis.sock chown redis:redis /var/run/redis/redis.sock chmod 770 /var/run/redis/redis.sock systemctl restart redis
- Test socket as
- Setting Reverts to OFF:
- Run permissions script:
Add:nano /home/newuser/public_html/fix_wp_permissions.sh#!/bin/bash cd /home/newuser/public_html find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; if [ -f wp-config.php ]; then chmod 600 wp-config.php fi if [ -d wp-content ]; then chmod -R 775 wp-content fi chown -R newuser:newuser . echo "WordPress permissions restored."chmod 700 /home/newuser/public_html/fix_wp_permissions.sh /home/newuser/public_html/fix_wp_permissions.sh echo "<Files fix_wp_permissions.sh> Deny from all </Files>" >> /home/newuser/public_html/.htaccess - Force via WP-CLI:
wp option patch update litespeed-cache-conf object 1 --path=/home/newuser/public_html
- Run permissions script:
- Enable Debug Logging:
- In LiteSpeed Cache > Toolbox > Debug Settings, set Debug Log to ON.
- Check:
cat /home/newuser/public_html/wp-content/debug.log
- Enable WP Debug:
- Edit:
Add:nano /home/newuser/public_html/wp-config.phpdefine('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false); - Check:
cat /home/newuser/public_html/wp-content/debug.log
- Edit:
- Plugin Conflicts:
- Deactivate:
wp plugin deactivate w3-total-cache wp-rocket redis-object-cache --path=/home/newuser/public_html
- Deactivate:
Security and Maintenance
- Secure Redis: In
/etc/redis.conf, setrequirepass yourstrongpasswordand update LiteSpeed Cache settings. - Monitor Redis:
systemctl status redis - Restart LiteSpeed:
systemctl restart lsws
Pro Tip: Combine with SEO optimization services and social media marketing for maximum site performance.
Key Takeaways
- Redis with LiteSpeed Cache drastically improves WordPress speed and SEO.
- Use
/var/run/redis/redis.sockfor fast object caching. - Leverage cPanel’s
redisgroup for scalable user access.
Contact us for help setting up LiteSpeed on your site.
FAQ
Does LiteSpeed Cache work with Redis?
Yes, Redis at /var/run/redis/redis.sock is the fastest way to enable object caching in LiteSpeed Cache.
Can I use a single user for all cPanel accounts?
No, cPanel’s security model uses separate users per account. Use the redis group to grant access to all cPanel users.
What if the Connection Test fails?
Check Redis status, socket permissions, and test connectivity with redis-cli -s /var/run/redis/redis.sock ping. Ensure the cPanel user is in the redis group.