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

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php53 .php .php7 .phtml
</IfModule>

For PHP 5.4

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php54 .php .php7 .phtml
</IfModule>

For PHP 5.5

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php55 .php .php7 .phtml
</IfModule>

For PHP 5.6

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php56 .php .php7 .phtml
</IfModule>

For PHP 7.0

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>

For PHP 7.1

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>

For PHP 7.2

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>

For PHP 7.3

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>

For PHP 7.4

<IfModule mime_module>
    AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>

And to install other PHP Extensions, refer our guide here for PHP Extesions Using EasyApache4.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS