CS-Cart: Enable Redis Caching on a cPanel Server Print

  • 0

Applies to: CS-Cart & Multi-Vendor on cPanel/AlmaLinux/Rocky/CentOS with LiteSpeed Web Server.
Goal: Use Redis for CS-Cart caching (and optionally sessions) when Redis is installed via the LiteSpeed WHM plugin.


Prerequisites

  1. Redis server installed and running via WHM → LiteSpeed Web Server → Plugins → Redis (or equivalent install).
  2. PHP Redis extension enabled for the domain’s PHP version (usually installed with the LiteSpeed Redis tool). If unsure, create a phpinfo.php and confirm you see a “redis” section.
  3. CS-Cart file access (cPanel File Manager or SSH) and ability to clear cache.

Step 1 — Verify Redis is running

  1. In WHM, open LiteSpeed Web Server → Redis and confirm the service status shows Running.
  2. Optionally check via SSH:
    redis-cli ping
    A healthy Redis replies with PONG.

Security note: Ensure Redis is bound to 127.0.0.1 (local only) and not exposed publicly. In most setups installed via the LS plugin, the default is localhost-only.


Step 2 — Confirm the PHP Redis extension

  1. In cPanel for the site, open Software → MultiPHP INI Editor (or use EasyApache 4 in WHM if managing globally).
  2. Create a test file phpinfo.php in your site’s document root with:
    <?php phpinfo(); ?>
    Load it in the browser and confirm the redis module is listed. Remove this file when you’re done.

Step 3 — Configure CS-Cart to use Redis for cache

CS-Cart’s main local settings file is config.local.php in your CS-Cart root directory.

  1. Open /home/USERNAME/public_html/path-to-cscart/config.local.php in the cPanel File Manager editor.
  2. Find the cache settings block (or add the lines if they don’t exist) and set Redis as the backend:
    // --- CS-Cart cache backend ---
    $config['cache_backend'] = 'redis';
    $config['redis_server']  = '127.0.0.1';
    $config['redis_port']    = 6379;
    
    // Optional: use a dedicated Redis database index (0–15 by default in Redis)
    // $config['redis_db'] = 1; // uncomment to use DB 1 for cache
    
    // Optional: Redis connection timeout (seconds)
    // $config['redis_timeout'] = 1.0;
    
  3. Save the file.

Tip: If you host multiple CS-Cart stores on the same server, use a different redis_db for each store to avoid key overlap.


Step 4 — (Optional) Store PHP sessions in Redis

You can keep sessions in the database (default) or move them to Redis. There are two reliable approaches; pick one:

Option A: CS-Cart session backend (preferred if your CS-Cart version supports it)

  1. Edit config.local.php again and add:
    // --- CS-Cart sessions in Redis ---
    $config['session_backend']      = 'redis';
    $config['session_redis_server'] = '127.0.0.1';
    $config['session_redis_port']   = 6379;
    
    // Optional: separate DB for sessions
    // $config['session_redis_db'] = 2;
    
    // Optional: session connection timeout
    // $config['session_redis_timeout'] = 1.0;
    
  2. Save the file.

Option B: PHP-level session handler (per domain)

  1. In cPanel for the domain, open Software → MultiPHP INI Editor (Editor Mode).
  2. Add or adjust:
    session.save_handler = redis
    session.save_path = "tcp://127.0.0.1:6379?database=2"
    
    Tip: Choose a different database index than you use for cache.
  3. Save. No code changes needed in config.local.php for this method.

Note: Only use one session method at a time. If you previously set $config['session_backend'], don’t also force PHP session handler via INI (and vice versa).


Step 5 — Clear CS-Cart cache

After changing cache or session configuration, clear CS-Cart cache so it rebuilds using Redis:

  1. Via URL query: append ?cc to your admin URL (e.g., /admin.php?cc) and load it once while logged in.
  2. Or delete cached files from var/cache (and var/themes_repository if needed) via cPanel File Manager:
    • Remove the contents of var/cache/ (do not delete the folder itself).

Step 6 — Validate Redis usage

  1. Functional check: Browse the storefront and admin; pages should load normally.
  2. Redis activity: Use the LiteSpeed Redis screen in WHM or SSH:
    redis-cli info keyspace
    redis-cli monitor   # (watch keys briefly; CTRL+C to exit)
  3. Optional PHP test:
    php -r '$r=new Redis(); $r->connect("127.0.0.1",6379); echo $r->ping(), PHP_EOL;'
    You should see PONG.

Troubleshooting

  • White page / 500 error after enabling Redis: Revert the last changes in config.local.php, clear cache, and confirm the PHP Redis extension is loaded (phpinfo). Then reapply settings carefully.
  • “Connection refused” or timeouts: Redis may not be running or not bound to 127.0.0.1. Check WHM → LiteSpeed → Redis status and the Redis configuration.
  • Session issues (users logged out unexpectedly): If you switched session storage, ensure only one session method is active (CS-Cart backend or PHP INI). Clear cache after any session change.
  • Key collisions across sites: Assign a unique redis_db per store (and a different DB for sessions if you separate them).
  • Performance tuning: In heavy stores, consider Redis persistence (AOF), maxmemory policies, and server RAM sizing. Keep Redis local-only for security.

Roll-Back (Disable Redis)

  1. In config.local.php, change:
    $config['cache_backend'] = 'file';
    and remove/comment any Redis lines you added for cache or sessions.
  2. If you used PHP session handler, remove the session.save_handler and session.save_path overrides from MultiPHP INI.
  3. Clear CS-Cart cache again and retest.

That’s it! Your CS-Cart store should now be using Redis for fast, memory-based caching (and optionally sessions), with Redis provided by the LiteSpeed WHM plugin on your cPanel server.


Was this answer helpful?

« Back