Skip to content

HTTP 502 Bad Gateway on cPanel when LiteSpeed or PHP-FPM is the culprit

A 502 on cPanel means the proxy front-end could not get an answer from the upstream — usually LiteSpeed or PHP-FPM. Here is the order of checks.

A 502 Bad Gateway on cPanel says the web server (Apache or LiteSpeed) tried to forward a request to an upstream worker (PHP-FPM, LSPHP, or a backend service) and got either no answer or a malformed one. Unlike a 500, the request never made it deep enough into PHP to log a traceback there. The fix path runs from the upstream backwards.

What’s happening

The chain is: client > Apache/LiteSpeed > upstream worker (PHP-FPM/LSPHP) > application. A 502 means the link between the web server and the upstream broke. Either the upstream is not listening on the expected socket, it timed out before responding, or it returned an unparseable response (usually because it crashed mid-request). The web server’s error log is where the upstream’s name and the failure mode appear.

How to verify

Find which upstream is failing:

# cPanel Apache log
tail -100 /usr/local/apache/logs/error_log | grep -i "bad gateway\|upstream"
# LiteSpeed log
tail -100 /usr/local/lsws/logs/error.log
# PHP-FPM pool status
ls /opt/cpanel/ea-php*/root/var/log/php-fpm/
systemctl status ea-php82-php-fpm
ps -eo pid,user,cmd | grep php-fpm
# socket listener
ss -lnp | grep php-fpm

If the upstream is alive but slow:

# response time on a known endpoint
curl -w "%{time_total}\n" -o /dev/null https://example.com/healthz

The fix

  1. PHP-FPM pool exhaustion — if pm.max_children is reached, new requests queue and eventually time out as 502. Raise pm.max_children in the PHP-FPM pool config (/opt/cpanel/ea-php82/root/etc/php-fpm.d/<user>.conf). Restart the pool.
  2. PHP-FPM crashed worker — journalctl -u ea-php82-php-fpm --since "1 hour ago". Look for segfault entries. Common cause: a buggy extension (opcache, xdebug, or a third-party one).
  3. LSPHP not running — LiteSpeed spawns LSPHP workers on demand. If a per-user lsphp is killed, the 502 hits only that user. Restart LiteSpeed: /usr/local/lsws/bin/lswsctrl restart.
  4. Backend service down — if the application proxies to a separate service (Node, Python, Ruby) via ProxyPass, that service is the upstream. Check systemctl status <service>.
  5. Timeout misalignment — if Apache’s ProxyTimeout is 60 seconds but the application takes 90, the worker is fine but Apache gave up. Raise ProxyTimeout to match the application’s max_execution_time.

A flaky 502 that hits one request in twenty under load is usually PHP-FPM pm.max_children set too low. Stack Harbor tunes these worker pools under cPanel/WHM management — start a conversation when 502s are intermittent.