Using a different PHP version for each website

Hosting123 uses CloudLinux as the operating system on our servers to increase server stability. One of the main features of CloudLinux is that each account can choose the PHP version they want to have for their website. This is very useful if you have an application that requires a specific PHP version. But the main drawback of these features is that you cannot set a different PHP version for a Plugin Domain or Subdomain in cPanel.

So how can you use a different PHP version for each website?

Your website may need to use a different PHP version than the PHP version assigned to your entire cPanel account. Although this is not possible using the PHP Selective UI, it is quite simple to do manually. You can configure the server to use different PHP versions across your subdomains and directories by adding SetHandler code to the folder’s .htaccess file to override the default PHP version.

Log in to your cPanel control panel.

Go to Files -> File Manager. If you want to edit the .htaccess file for your addon domain, locate the .htaccess file for that addon domain and navigate to the public_html/ folder.

Once in the File Manager, make sure the “Show hidden files” option is enabled. This will allow you to see the .htaccess file if it is hidden.

To set a custom PHP version for your desired directory/additional domain, select the .htaccess file and click Edit from the toolbar, or click the file to create a new .htaccess file if it does not exist.

Once inside the .htaccess file, enter the PHP handler of the version you want to use. If there is already a handler in the file it should be deleted or replaced with your new handler. Change the SetHandler line in the code depending on the PHP version you want to use for your specific application. The handler looks like this:

For PHP7.4;

AddHandler application/x-httpd-alt-php74___lsphp .php

Add/modify the following line in your .htaccess file depending on the version you want to use

For PHP 5.6;

AddHandler application/x-httpd-alt-php56___lsphp .php

After adding your configuration rules, save your changes and close the .htaccess file.
Your specific PHP version is now set. As a result, a plugin domain/directory, for example, will use the PHP 7.4 version you set for it, not the public version set for the account in cPanel > PHP Chooser.

If you want to set a different PHP version for a subdomain, the process is similar. Now you know how to easily change the PHP version in your Addon domains using one of the handlers below depending on the PHP version you want.

Leave a Reply 0

Your email address will not be published. Required fields are marked *