Skip to content

Switching the PHP session handler to Redis on a cPanel server

How to point one or more cPanel accounts at a Redis-backed session handler for PHP-FPM, including the Redis install, the session.save_path syntax, and the failure mode if Redis goes away.

PHP’s default session handler is filesystem-based: each session is a file in /var/lib/php/session or /home/<user>/tmp. On a single-server cPanel host that works fine. On a load-balanced pair of cPanel servers, or on any setup where sessions need to survive across multiple PHP-FPM pools, the filesystem handler does not scale. Pointing PHP at Redis is a one-line change per account once Redis is installed.

What’s happening

session.save_handler = redis plus session.save_path = "tcp://127.0.0.1:6379" tells PHP to send session writes to a Redis instance instead of the local filesystem. Sessions become a key-value pair: the session ID is the key, the serialized session data is the value. Redis handles TTL via session.gc_maxlifetime. The phpredis extension is required for PHP to speak the Redis protocol; cPanel ships it as ea-php<ver>-php-redis.

How to verify

Confirm the prerequisites:

rpm -qa | grep ea-php82-php-redis
systemctl status redis
ss -tlnp | grep :6379
php -r 'echo extension_loaded("redis") ? "yes" : "no";'
grep -E "^session\." /opt/cpanel/ea-php82/root/etc/php.ini

If redis is not in the loaded extensions list, the phpredis RPM is not installed (or installed but not enabled for the version).

The fix

  1. Install Redis if not present: yum install -y redis && systemctl enable --now redis. Confirm it is listening on 127.0.0.1:6379 only — never expose Redis on a public interface without auth.
  2. Install the PHP extension: yum install -y ea-php82-php-redis. Verify it loaded: php -m | grep redis.
  3. Per account, configure the session handler via MultiPHP INI Editor > Basic Mode > add:
    session.save_handler = redis
    session.save_path = "tcp://127.0.0.1:6379?weight=1&timeout=2.5"
    session.gc_maxlifetime = 1440
    The query parameters: weight matters only with multiple servers; timeout is how long PHP waits for Redis on each call.
  4. Reload the FPM pool: systemctl reload ea-php82-php-fpm.
  5. Validate. From the account’s docroot, place a one-line probe:
    <?php session_start(); $_SESSION['t'] = time(); echo ini_get('session.save_handler');
    Hit it once, then check Redis: redis-cli KEYS 'PHPREDIS_SESSION:*'. There should be one entry per session.
  6. Plan for the Redis-unavailable case. If Redis is down, every request to that account fails with a 500 from session_start(). Either run Redis with persistence and a systemd restart policy, or accept that Redis is now a first-class dependency for those accounts.

For environments where session sharing across hosts is required, Stack Harbor sets up Redis-backed sessions during onboarding under environment management.