First, you can select your preferred PHP version across the hosting account from cPanel as explained in this article (How to change PHP version and extensions).
You can select a different PHP version on each folder under your hosting account. This allows you to run different PHP scripts with different requirements on the same account.
To do so, use the following code in .htaccess file inside the folder in question:
<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$"> SetHandler application/x-httpd-alt-php80___lsphp </FilesMatch>
Note: This code will use alt-php provided by CloudLinux.
The above code will use PHP 8.0. To change the version, edit the last part of the second line of the code php80
If you want to run PHP 7.4 change php80 to php74 and if you want to run PHP8.1, change php80 to php81 and so on.
You can enable/disable PHP modules for all PHP versions from cPanel > "Select PHP version" interface.
