In some cases, default server settings may not be suitable for your website configuration and setup. Sometimes you may need to change your PHP version to resolve some errors. This tutorial shows how to change your PHP version in cPanel.
What you’ll need
Before you begin this guide you’ll need the following:
- Access to your hosting account’s cPanel
Step 1 — Opening up PHP Settings
Log in to your cPanel and navigate to Select PHP Version:
You will now come to this screen:
Step 2 — Selecting Your PHP Version
Section 2 in the image above is where you can change your PHP version. Once you have selected one, make sure to click 'Set as Current'. Then just click Save at the bottom.
Do you have a single domain or wish to use different PHP version per folder? Do you have an installed PHP 5.x software in a folder/blog and want to use a PHP 7.x instead? If so, you can do this using cPanel and the .htaccess file.
You can also set the version per domain using .htaccess.
The best way to change the version of PHP used for requests to your website is to add one of the following lines to your .htaccess file. One major convenience of this method is that you can change the PHP version for individual directories.
AddHandler application/x-httpd-php74 .php
AddHandler application/x-httpd-php73 .php
AddHandler application/x-httpd-php72 .php
AddHandler application/x-httpd-php71 .php
AddHandler application/x-httpd-php70 .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php55 .php
AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php53 .php
You have now learnt how to change your PHP version in cPanel. We recommend using either 7.2 - 7.4 for the best results however, depending on the age of your website or script, you may need to choose an older version for it to function correctly.
Note that these settings can solve most issues you are facing with your website after initial transfer or setup. You may also need to look at your website HTML/PHP code also depending on the issue you face.