Well you can change the PHP version through cPanel easily and you can also change the PHP directory basis. For example for some directories if you want to keep PHP version 5.6 you can select those directories and set php version in cPanel.
Important Note: If your server doesn’t have the PHP version installed which you may try to change through .htaccess. In that case your website can go down. So make sure you are doing this through FTP or Hosting Panel not WordPress admin. In case any problem you can easily remove the code you insert.
So when you change the PHP version from cPanel. cPanel adds a code into .htaccess file. That code changes the PHP version for directory in which .htaccess file is. Also it changes the PHP version of all sub directories unless the inner directory have unique PHP version code.
Change PHP version via .htaccess file code
You need to edit the .htaccess file if that doesn’t exist please create new. While creating the new .htaccess file make sure there is nothing before . and after htaccess. You can say this file have the extension .htaccess but have no name. This file have instructions for Apache server to perform the tasks. For example handling the Permalinks in WordPress.
Edit .htaccess file via cPanel
Before you can view the file the hidden files should be selected to visible in cPanel file manager settings. After that edit the .htaccess file and add the code below.
Edit .htaccess file via FTP
Use your favorite FTP client we use Filezila. Download the .htaccess file and edit file in any text editor or code edit. Add the code below and you are done to re upload.
Code to place in .htaccess for changing PHP version
Let’s take a look to code which you have to place in your .htaccess file. Make sure you place it at end of the .htaccess file to avoid any type of problem. Do not include between any other code.
# Use PHP74 as default
AddHandler application/x-httpd-php74 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php74/lib
</IfModule>
The PHP74 defines the PHP version 7.4 , and you can change the 74 to your desired PHP version. Remember your server or host should also support that PHP version.
If you have any web related issues you can try our WordPress maintenance service for a month.