Why do you need multiple PHP versions in the same hosting account?
There’re many web applications , only runs stably with a specific PHP version. For example a chat web based program like yshout runs on PHP version 5.3 or older, a forum script like discuz runs on PHP 7.0 or older, a shopping website using wordpress + woocommerce requires the latest secured PHP version ( 7.4.8 or later ).
Why don’t developers up-to-date their scripts?
That’s a good suggestion. But I think change to latest PHP version needs so much works. New technology needs new function and library… and so many working days. And with the older php version, the application still running well, or simply thing is their team disbanding.
How could you maintain multiple apps in shared hosting ?
You’re starter, start your business project with a small budget ( $100 or less ). You could create many many virtual machine, VPS, servers when your budget’s bigger.
You could apply multiple php versions in your hosting account by cPanel’s Select PHP version tool and an .htaccess commands. I will use stablehost for this tutorial
Use .htaccess to drive your right php version
After you confirmed a php version, the hosting provider will apply your selected php version to all apps in your account.
<IfModule mime_module> AddHandler application/x-httpd-alt-php70 .php .phtml </IfModule>
That’s how I choose specific version of php for my website, just add that code into .htaccess file. Save and upload to your website root folder
<IfModule mime_module> ##add this line to tell hosting provider run right version of php ##AddHandler application/x-httpd-alt-phpXX .php .phtml ## XX two digits stand for version of php. AddHandler application/x-httpd-alt-php56 .php .phtml </IfModule>
This trick works perfectly in my shared hosting at stablehost.
This post has my referral link to register a stable hosting!!!