Skip to content

What is lsphp? LiteSpeed PHP on cPanel and how to switch

lsphp is the PHP process LiteSpeed starts for each cPanel account. Check which PHP handler an account really uses and switch it to LSAPI safely.

lsphp is the PHP process that LiteSpeed Web Server starts to run your sites’ PHP code. If top or ps on a cPanel server shows many lsphp processes, each group belongs to one account and runs as that account’s Unix user. LiteSpeed creates them, passes them requests over its own interface, LSAPI (the LiteSpeed Server API), and stops them when they sit idle. The alternative on the same server is PHP-FPM, a separate PHP service that LiteSpeed reaches through an extra proxy hop. Many cPanel accounts end up on PHP-FPM without anyone choosing it, because cPanel’s per-domain PHP-FPM switch overrides the handler set for the PHP version. Moving an account to lsphp therefore takes two changes: turn PHP-FPM off for the domain, then set the handler for its PHP version to lsapi. The only reliable proof is what PHP itself reports as its server API when you reach it over HTTP.

What you’ll accomplish

  • Tell, from the shell, which web server is actually serving requests and which handler each cPanel account is really running under, rather than trusting what the panel says.
  • Move one account, or the whole server, from the PHP-FPM proxy path to LSAPI, in the right order, so no domain is left with neither handler active.
  • Size the lsphp process pool with LSAPI_CHILDREN and the External App connection limit so a busy site does not consume the memory the rest of the box needs.
  • Anticipate the three things that change underneath the switch: suEXEC ownership enforcement, where per-account php.ini overrides come from, and a cold opcache.
  • Confirm the result with a single unambiguous signal instead of a plausible-looking one.

Prerequisites

Root shell access on a cPanel and WHM server, version 110 or later. The WHM interfaces used here (MultiPHP Manager, MultiPHP INI Editor) have been stable across recent versions, though the exact position of the system-wide handler control has moved between releases.

LiteSpeed Web Server Enterprise installed with the cPanel plugin, with a licence that is current. LSWS Enterprise reads Apache’s configuration directly and is the version that supports LSAPI, PHP-FPM proxying and .htaccess alike. OpenLiteSpeed on cPanel is a different product with a different plugin: it only ever runs PHP through LSAPI, so there is nothing on it to switch, and most of the WHM handler controls simply do not apply.

At least one EasyApache 4 PHP version installed, and a matching lsphp binary built for it. The LiteSpeed cPanel plugin builds these; without one, setting the handler to lsapi for that version will produce 503s rather than a faster site.

A maintenance window, even a short one. The change restarts PHP for every affected domain, and the first requests after it are slower because the opcode cache starts empty.

How it works

A PHP request has to reach a PHP process somehow. The handler is the name for how that happens, and the two candidates on a LiteSpeed-equipped cPanel box differ in how many hops the request takes and, more importantly, in who owns the process at the far end.

Under LSAPI, there is no separate PHP service. LiteSpeed’s own worker holds a Unix socket, and behind that socket sits a small group of lsphp processes that LiteSpeed forked, will supervise, and will reap when they go idle or hit their request ceiling. Those processes run as the cPanel account’s user, set by suEXEC at fork time. There is one such group per account per PHP version, which is why ps on a busy shared server shows dozens of lsphp processes owned by dozens of different users.

Under PHP-FPM, the far end is a service LiteSpeed does not control. The php-fpm master, started by systemd, owns a pool per domain and decides on its own when to spawn and retire workers, following the pm.* directives in that pool’s configuration file. LiteSpeed reaches it the same way Apache would, through the FastCGI proxy path, which is the extra hop in the diagram below.

Side-by-side request paths comparing LiteSpeed with the LSAPI handler, where a single hop reaches an lsphp child owned by LiteSpeed and running as the account user, against LiteSpeed with PHP-FPM, where two hops reach a pool worker owned by the php-fpm master

The extra hop is real but it is not usually the headline. What matters more is ownership. LiteSpeed knows exactly how many PHP processes exist because it made them, so it can throttle, queue and kill them in step with its own concurrency limits. With PHP-FPM, two systems size pools independently and neither can see the other’s queue, which is how a server ends up with idle web workers and saturated PHP workers at once.

The reason so many accounts sit on the FPM path anyway is a defaults problem, not a decision anybody made. EasyApache 4 predates the LiteSpeed plugin on most servers and configures PHP as if Apache were the web server. cPanel then treats PHP-FPM as a separate, higher-priority switch: if PHP-FPM is on for a domain, the domain uses PHP-FPM regardless of what the PHP version’s handler is set to. So an administrator can set the handler to lsapi, see it saved, and change nothing at all for any domain that has the FPM toggle on. That precedence is the single most common reason a switch appears to fail.

For a comparison of the two execution models on their merits, rather than the cPanel mechanics of choosing, see LiteSpeed PHP via LSAPI vs PHP-FPM.

Step-by-step

1. Confirm which web server is actually listening. Everything else depends on this answer, and it is not always the one on the invoice.

/usr/local/lsws/bin/lswsctrl status

A healthy LiteSpeed box replies with something like litespeed is running with PID 24187. If it says litespeed is not running, or the binary does not exist, Apache is serving and LSAPI is not available to you. Cross-check what owns the socket:

ss -ltnp | grep -E ':(80|443)\b'
LISTEN 0  128  0.0.0.0:80   0.0.0.0:*  users:(("litespeed",pid=24187,fd=9))
LISTEN 0  128  0.0.0.0:443  0.0.0.0:*  users:(("litespeed",pid=24187,fd=11))

If httpd holds those sockets, stop here. The decision tree below covers the three cases, including the one where the right answer is to leave the server alone.

Decision tree keyed on which web server is running: Apache means do not switch, LiteSpeed Enterprise means switch to LSAPI with PHP-FPM off, OpenLiteSpeed is already on LSAPI, with the WHM or OpenLiteSpeed setting that changes each

2. Check that an lsphp binary exists for each PHP version in use. Setting the handler to lsapi for a version with no matching binary takes the site down.

ls -1 /usr/local/lsws/lsphp*/bin/lsphp /opt/cpanel/ea-php*/root/usr/bin/lsphp 2>/dev/null

You want at least one path back per PHP version your accounts run. If the list is empty, the LiteSpeed cPanel plugin has not built the binaries yet; do that from WHM before touching any handler setting.

3. Read the handler that is currently set per PHP version.

whmapi1 php_get_handlers
---
data:
  version_handlers:
    -
      available_handlers:
        - cgi
        - lsapi
        - none
      current_handler: cgi
      version: ea-php82
metadata:
  command: php_get_handlers
  reason: OK
  result: 1

current_handler is the version-wide setting. It is not the whole story, which is the next step.

4. Read the per-domain PHP-FPM state, because it wins.

whmapi1 php_get_vhost_versions | grep -E 'vhost|php_fpm|version'
      php_fpm: 1
      version: ea-php82
      vhost: example.com
      php_fpm: 0
      version: ea-php82
      vhost: staging.example.com

Any vhost showing php_fpm: 1 is going through the proxy path no matter what step 3 reported. These are the domains you actually have to change.

5. Confirm from the running processes, not the configuration. Configuration describes intent; process tables describe reality.

ps -eo user,pid,rss,comm --sort=-rss | grep -E 'lsphp|php-fpm' | head
acmecorp  20718  71204 lsphp
acmecorp  20719  68880 lsphp
root      11902  12440 php-fpm
example   11994  58116 php-fpm

Root-owned php-fpm is the master; the account-owned ones are pool workers. lsphp processes owned by an account user mean that account is already on LSAPI.

6. Turn PHP-FPM off for the domains you are moving. In WHM, go to Software, then MultiPHP Manager. In the domain list, select the affected domains and set PHP-FPM to off, then apply. Do this before changing the version handler: with FPM still on, the handler change is inert, and you will spend the next twenty minutes debugging a setting that did nothing.

7. Set the version handler to LSAPI. Still in MultiPHP Manager, open the PHP Handlers section, find the PHP version, and set its handler to lsapi. Repeat for every version your accounts use. From the shell the same change is:

whmapi1 php_set_handler version=ea-php82 handler=lsapi
---
metadata:
  command: php_set_handler
  reason: OK
  result: 1

8. Restart LiteSpeed so it rereads the generated configuration.

/usr/local/lsws/bin/lswsctrl restart
[OK] Send SIGUSR1 to 24187

LiteSpeed’s restart is graceful: existing connections finish on the old workers while new ones go to the new ones. It is not a hard cut, but it is also not free of effect, because the new workers start with no cached opcodes.

9. Size the process pool deliberately. LSAPI’s concurrency has two knobs that must agree with each other. LSAPI_CHILDREN is an environment variable on the External App definition and sets how many children a single lsphp parent may fork. Max Connections, on the same External App, sets how many simultaneous requests LiteSpeed will send to it. Set them to the same number: if Max Connections is higher, LiteSpeed queues requests the app can never serve; if LSAPI_CHILDREN is higher, you are paying memory for children that will never receive work. Both live in the LSWS WebAdmin console, reachable from WHM under Plugins and LiteSpeed Web Server, at Server Configuration, then External App.

Resist the temptation to raise the number until the errors stop. On a shared box, each lsphp child is a resident PHP process with its own memory footprint, and there is one child group per account. Multiplying a generous per-account ceiling by the number of accounts is how a server that was merely slow becomes a server that is out of memory. Start from measured peak concurrency for the account, not from the number that made the error go away.

LSAPI_MAX_IDLE is worth setting alongside them: it retires children idle for that many seconds, keeping the resident set proportional to real traffic rather than to yesterday’s peak.

Validate it works

The single unambiguous test is to ask PHP, over HTTP, what SAPI it is running under. Nothing else distinguishes the two handlers reliably: the response headers say LiteSpeed either way, because LiteSpeed is the web server in both cases.

echo '<?php echo PHP_SAPI, PHP_EOL;' > /home/acmecorp/public_html/sapi-check.php
chown acmecorp:acmecorp /home/acmecorp/public_html/sapi-check.php
curl -s https://example.com/sapi-check.php
rm -f /home/acmecorp/public_html/sapi-check.php
litespeed

litespeed means the request was served by an lsphp process over LSAPI. fpm-fcgi means you are still on the proxy path and something in steps 6 and 7 did not apply. Remove the file immediately either way; the same value appears in the Server API row of phpinfo() if you prefer that output, and the same caution applies.

Then confirm the process side matches, for the specific account:

ps -o user,pid,rss,etimes,comm -C lsphp | grep acmecorp
acmecorp  30412  62108   184 lsphp
acmecorp  30413  58996   184 lsphp

The etimes column shows seconds since the process started, so a small number here confirms these children were forked after your restart rather than being left over from before it.

Finally, check that the site is serving normally and that the LiteSpeed cache layer, if you use it, is still engaged:

curl -sI https://example.com/ | grep -iE '^(server|x-litespeed-cache)'
server: LiteSpeed
x-litespeed-cache: hit

The server header only tells you LiteSpeed answered. Treat the PHP_SAPI result as the verdict.

Troubleshooting

The handler says lsapi but PHP still reports fpm-fcgi. PHP-FPM is still enabled for that domain and takes precedence. Recheck with whmapi1 php_get_vhost_versions and look for php_fpm: 1 on the vhost in question. Turning it off in MultiPHP Manager for the domain resolves it. This accounts for most reports that “the switch did nothing”.

503 Service Unavailable on every PHP page immediately after the change. LiteSpeed could not start an lsphp process for that version. The usual cause is a missing binary, found in step 2, or a version mismatch after a PHP upgrade replaced the ea-php tree without rebuilding lsphp. Check /usr/local/lsws/logs/stderr.log and /usr/local/lsws/logs/error.log; a failed exec is logged there with the path it tried.

Uploads or cache writes start failing with permission errors that were not there before. This is the suEXEC edge, and it is subtler than the folklore suggests. cPanel’s PHP-FPM pools already run as the account user, so the effective UID usually does not change. What changes is enforcement: suEXEC refuses to run when the document root or the script is group- or world-writable, and files left behind by a root cron, a sudo unzip, or a legacy mod_php era are owned by root or nobody rather than the account. Those files were tolerable before and are unwritable now. Fix ownership rather than loosening permissions:

chown -R acmecorp:acmecorp /home/acmecorp/public_html
find /home/acmecorp/public_html -type d -perm /022 -exec chmod 755 {} +

A php.ini value you set is no longer in effect, or one you forgot about suddenly is. The two handlers read overrides from different places. PHP-FPM ignores php_value and php_admin_value in .htaccess entirely and takes per-domain settings from the pool file under /opt/cpanel/ea-php82/root/etc/php-fpm.d/. LSWS Enterprise honours those .htaccess directives. So a pool-file override stops applying the moment you switch, and a dormant .htaccess line written years ago starts applying. Reconcile both before the window closes; MultiPHP INI Editor in WHM shows the version-level values but not either per-domain layer. A .user.ini file works under both handlers and is the more portable place to put per-site values.

The site is measurably slower for the first few minutes. Opcache is per process group, and the switch created new process groups, so every file is compiled from source again on first request. That is expected and self-correcting. If it does not settle, opcache may not be sized for the new arrangement: under LSAPI there is one shared memory segment per account rather than per FPM pool, so opcache.memory_consumption is multiplied by the number of accounts, not shared across them. On a dense shared box, that total is worth calculating before you raise it.

PHP processes accumulate and never exit. That is a different problem from handler selection, and killing them is only triage. See stuck lsphp processes on a cPanel server for finding what they are blocked on.

When this is the wrong approach

If Apache is the active web server, none of this applies. There is no lsphp handler under Apache, and the LSAPI entry will not appear in MultiPHP Manager. Your choice there is between PHP-FPM and a suEXEC CGI handler, and PHP-FPM is almost always the better one.

If you run OpenLiteSpeed, the switch is already made. OpenLiteSpeed executes PHP through LSAPI exclusively and does not read .htaccess the way LSWS Enterprise does, so the tuning happens per vhost in its own admin console rather than through the WHM controls above.

If the site’s problem is a slow database, an uncached page, or a plugin doing remote HTTP calls inside the request, changing the handler will not move the number that matters. Removing one proxy hop shaves a small, fixed cost off each request; it does nothing about a four-second query. Measure where the time actually goes first.

And on a dense shared box, model the memory before you switch a hundred accounts at once. One resident child group per account behaves differently under pressure than FPM pools that can be configured to scale to zero. Move a handful of accounts, watch memory for a full traffic cycle, then decide.

The cPanel side of this is documented at docs.cpanel.net and the LiteSpeed side at docs.litespeedtech.com.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.