How to Switch Php Version in Magento
Magento allows a unique server setup that allows each customer to select which version of PHP to use or switch PHP version in Magento.
Magento 2 supports these Php versions for now: PHP 5.6, PHP 7.0, PHP 7.1, PHP 7.2 & PHP 7.3 (for Magento 2.3.3).
To change the PHP version in Magento in your hosting account, follow the steps below:
- Log in to cPanel for your account
- Navigate to 1H Software section -> PHP Version Manager
- Go to the directory you would like to change the PHP version for (please note that this change applies to subdirectories for it also)
- Click on the directory name
- Choose the desired PHP version
- Click Save
Make the most out of the Managed PHP version service. Automatically update your PHP version to the latest, steady, and secure one when available.
To implement it, select the Managed PHP Version option and Save. It will add the following handler in your .htaccess file:
AddHandler application/x-httpd-recommended-php .php .php5 .php4 .php3
It makes sure that your store is always running on the recommended PHP version without any implementations from your side.
Another option is to apply the changes manually without the help of the PHP version manager in cPanel by adding one of the below directives in the .htaccess file of your store:
Switch to PHP 7.3
AddHandler application/x-httpd-php73 .php .php5 .php4 .php3
Switch to PHP 7.2
AddHandler application/x-httpd-php72 .php .php5 .php4 .php3
Switch to PHP 7.1
AddHandler application/x-httpd-php71 .php .php5 .php4 .php3
Switch to PHP 7.0
AddHandler application/x-httpd-php70 .php .php5 .php4 .php3
Switch to PHP 5.6
AddHandler application/x-httpd-php56 .php .php5 .php4 .php3
If you want a different version of PHP in a subdirectory, create a new .htaccess file in it with the directive for the desired PHP version.
Note: Please make sure that the above PHP versions are installed on your server before applying the above method.