2 Ways to Change PHP Version per Domain – .htaccess or MultiPHP

Almost all hosting control panel software offer multiple PHP versions to serve websites. You can change PHP version per domain using MultiPHP Manager offered by the control panel. However, if the MultiPHP Manager is unavailable then you can set the same using the domain’s .htaccess file.

Popular control panels like WHM/cPanel, Plesk and CentOS Web Panel offer an easy interface to install multiple PHP versions. So first of all, you need to install all desired PHP versions. Just, telling “how to set up multiple PHP versions” is currently out of the scope of this article.

Change PHP Version per Domain

Before we proceed, if you experience trouble running your website after the version change then check the local PHP configuration as well. It might not be in working status. Here is an article specifying the PHP configuration trouble and the solution

1. PHP Version per Domain using MultiPHP Manager

The inbuilt MultiPHP Manager is the easiest way to set PHP versions for each domain in your hosting account. However, the interface to manage may vary from the control panel to the control panel. For example, if you have full administration on WHM/cPanel then the path is WHM → Home → Software → MultiPHP Manager.

However, most control panels don’t offer this feature in shared and cloud hostings. Luckily, you have another option in that case. You can set PHP Version per domain using .htaccess as well.

2. Change PHP Version for a Domain using .htaccess

You can switch to a different PHP version by specifying code in the .htaccess file. You need to add a handler to change the PHP version rather than the system default. Suppose the default version in your hosting account is PHP 7.0. Further, you wish to change it to 7.3. So open the .htacess file and add the following line to either beginning or at the end there.

Similarly, below is the list of handlers for various PHP version supported by hosting control panels.

Easy that? Also, you’re not limited to just the domain. You can change PHP version per user account or the directory. Just create a .htacess file directly inside the directory if there is no one. Then add the handler code to set the specific PHP version for all domains/websites hosted inside that.

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.