Redis Object Cache Setup Guide for LiteSpeed Cache in WHM/cPanel

Redis Object Cache Setup Guide for LiteSpeed Cache in WHM/cPanel

Redis Object Cache Setup Guide for LiteSpeed Cache in WHM/cPanel

Redis Object Cache Setup Guide for LiteSpeed Cache in cPanel

By |

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.conf configured with:
    
    bind 127.0.0.1
    port 6379
    unixsocket /var/run/redis/redis.sock
    unixsocketperm 770
              
    Restart Redis: systemctl restart redis
  • LiteSpeed Web Server installed in cPanel/WHM.
  • PHP Redis extension installed:
    yum install ea-php84-php-redis; systemctl restart lsws
    Adjust for your PHP version (e.g., ea-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:

  1. Log in to WHM (https://yourserver.com:2087).
  2. Go to Account Functions > Create a New Account.
  3. 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.
  4. Click Create.
  5. Verify the user is in the redis group (via hook /usr/local/cpanel/hooks/postwwwacct/10-add-to-redis-group):
    groups newuser
    If redis is missing, add manually as root:
    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:

  1. Log in to cPanel (https://yourdomain.com/cpanel).
  2. Install WordPress (via cPanel > WordPress Toolkit or manually).
  3. Install LiteSpeed Cache in WordPress admin (https://yourdomain.com/wp-admin):
    • Go to Plugins > Add New, search for "LiteSpeed Cache", install, and activate.
  4. Go to LiteSpeed Cache > Cache > Object.
  5. 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.
  6. Click Save Changes and verify Connection Test: Passed.
  7. If it fails, try TCP:
    • Host: 127.0.0.1
    • Port: 6379
  8. Test functionality:
    • Purge caches (LiteSpeed Cache > Toolbox > Purge All).
    • Visit https://yourdomain.com and 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:
      redis-cli -s /var/run/redis/redis.sock ping
      Expected: PONG
    • Test PHP connection:
      
      echo '<?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.php
                    
      Access https://yourdomain.com/redis_test_sock.php. Expected: string(5) "+PONG" or bool(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
                    
  • Setting Reverts to OFF:
    • Run permissions script:
      
      nano /home/newuser/public_html/fix_wp_permissions.sh
                    
      Add:
      
      #!/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
  • 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:
      nano /home/newuser/public_html/wp-config.php
      Add:
      
      define('WP_DEBUG', true);
      define('WP_DEBUG_LOG', true);
      define('WP_DEBUG_DISPLAY', false);
                    
    • Check:
      cat /home/newuser/public_html/wp-content/debug.log
  • Plugin Conflicts:
    • Deactivate:
      wp plugin deactivate w3-total-cache wp-rocket redis-object-cache --path=/home/newuser/public_html

Security and Maintenance

  • Secure Redis: In /etc/redis.conf, set requirepass yourstrongpassword and 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.sock for fast object caching.
  • Leverage cPanel’s redis group 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.

We are a full service Internet Marketing Firm

Located in Springfield, MO. Google AdWords and Analytics Certified.

Have Questions? Start a Project
Book a Call