How to change PHP version thru Cpanel or .htaccess?

Change PHP version Cpanel
Change PHP version Cpanel

You can easily change the PHP version of your site by logging into your Cpanel hosting account. Here are the steps:

  1. Log in to cPanel for your account
  2. Go to Software section -> PHP Version Manager or PHP Configuration
  3. Choose the version you want to use from the dropdown (pls note that this change will also apply to all the subdirectories inside)
  4. Once chosen, save the option.

This will automatically add a line similar to the one below to your .htaccess file located in your root folder.

AddHandler application/x-httpd-recommended-php .php .php5 .php4 .php3

You can also make the change without using the PHP Version Manager. To do this, access your root folder either through Cpanel > File Manager or directly through FTP using a software like Filezilla.

You can also apply the changes manually, without using the PHP Version Manager in cPanel. To do so add one of the following directives in the .htaccess file of your website:

For changing to PHP 7.4

AddHandler application/x-httpd-php74 .php .php5 .php4 .php3

For changing to PHP 7.3

AddHandler application/x-httpd-php73 .php .php5 .php4 .php3

For changing to PHP 7.2

AddHandler application/x-httpd-php72 .php .php5 .php4 .php3

For changing to PHP 7.1

AddHandler application/x-httpd-php71 .php .php5 .php4 .php3

For changing to PHP 7.0

AddHandler application/x-httpd-php70 .php .php5 .php4 .php3

For changing to PHP 5.6

AddHandler application/x-httpd-php56 .php .php5 .php4 .php3

Note that this will change the PHP version not just for the folder/site but also for all of its sub folders.