Multiple PHP versions on one cPanel account

One of our clients ran their own dedicated cPanel server and was generally happy with it. There was one problem, though, that neither their provider nor they themselves could solve: they wanted to run a different PHP version in each subfolder under a single domain. One folder held an older application that only worked with old PHP, while the rest of the website already needed a newer version.

Starting point

As a first step, we surveyed the server: what was installed on it and how, focusing on the web server. It turned out that

  • the Apache web server was running, with PHP served by PHP-FPM,
  • the provider had put its own Nginx-based cache (not one shipped with cPanel) in front of Apache.

Why doesn’t it work with PHP-FPM?

cPanel sets the PHP version per domain in MultiPHP Manager. With PHP-FPM, each domain has its own FPM pool that runs a single PHP version, so within a domain you can’t use a different one per folder.

The other difference: PHP-FPM doesn’t read the PHP settings in .htaccess files (php_value, php_flag); these have to be set in a .user.ini file or in MultiPHP INI Editor. This will matter later on.

Solution: mod_lsapi

After reviewing the website’s traffic and load, we decided to install the free mod_lsapi Apache module on the server. In our tests and experience, its performance is roughly similar to PHP-FPM, but it has a feature that was needed here: the PHP version can be set down to individual folders.

On a cPanel server, mod_lsapi can be installed as an EasyApache 4 package (ea-apache24-mod_lsapi), and it can be selected as the PHP handler in MultiPHP Manager. The version is then determined by the folder’s .htaccess file, in the same form that cPanel itself writes:

# public_html/legacy-app/.htaccess
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>

Another AddHandler line in the domain’s root (for example ea-php81) sets the version for the rest of the site, and the folders override it.

Step by step

We didn’t switch over the whole server. First, we disabled PHP-FPM (and so moved to mod_lsapi) only for the domains that needed this feature; the other domains stayed on PHP-FPM.

Not everything went smoothly at first: the .htaccess files still contained settings belonging to old PHP versions. Under PHP-FPM these caused no trouble, because FPM doesn’t load them – but mod_lsapi does, and they caused errors. Once the .htaccess files were cleaned up, everything worked properly. The Nginx cache in front of Apache wasn’t affected by the change.

Result

  • Under a single domain, each folder runs its own PHP version.
  • Based on the tests, neither the website’s speed nor the server’s load changed measurably.
  • The other domains stayed on PHP-FPM, unchanged.

Looking back from 2026

The solution still works today, but old PHP versions are an ever-growing risk: PHP 7.4 support ended in November 2022, and since then it hasn’t even received security fixes. If an application still needs old PHP, it’s worth separating it from the rest of the website. That’s what our own project, PHP EOL, is for: Docker images for PHP versions 5.2–8.2, with backported security fixes.

We write more about running cPanel servers on the For hosting providers page.

Let’s talk about your project

Tell us briefly how we can help, and we will get back to you as soon as we can.

Get in touch