How to change the PHP version of a subdomain in cPanel

Choosing a PHP Version for a Specific Directory.

To set a different PHP version from the one assigned to your domain on your cPanel account you need to add a special code to your .htaccess file.

NOTE: The .htaccess file is a hidden file that is read by the webserver.

To edit the .htaccess file.

  1. Navigate to the section Files and Select File Manager.
  2. If you wish to edit .htaccess file for your main domain navigate to the public_html folder.
  3. For the addon domain, go to the public_html/youraddondomain.com folder.

Once you are in the File Manager, make sure that you have Show hidden files enabled.

Filemanegr

To set a custom PHP version for your desired directory, either select the .htaccess file and click on Edit from the toolbar or right-click over it and choose the option to Edit the file.

Filemanegr

A pop-up window will appear, where once again you need to click on Edit.

Note! There is one little trick that can be confusing. It applies only if you have PHP Selector enabled and you have non-native version selected there for a user. In that case, if the version that you assign through .htaccess is the same as ea-php version selected as system default version in MultiPHP Manager -> System Default version, that version will not be applies, the version that you'll actually get will be the same as selected in PHP Selector.

(From: https://cloudlinux.zendesk.com/hc/en-us/articles/115004537805-Different-PHP-versions-per-directories-using-mod-lsapi)

Available PHP Handlers.

Now that you are inside the .htaccess file, аt the top of the file, insert the PHP handler for the version you would like to use.

For PHP 5.3

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php53-lsphp
</FilesMatch>

For PHP 5.4

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php54-lsphp
</FilesMatch>

For PHP 5.5

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php55-lsphp
</FilesMatch>

For PHP 5.6

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php56-lsphp
</FilesMatch>

For PHP 7.0

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php70-lsphp
</FilesMatch>

For PHP 7.1

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php71-lsphp
</FilesMatch>

For PHP 7.2

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php72-lsphp
</FilesMatch>

For PHP 7.3

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php73-lsphp
</FilesMatch>

For PHP 7.4

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-httpd-ea-php74-lsphp
</FilesMatch>