How to Set Custom PHP Version per Directory

The PHP version is important not only for speed and performance. There are different applications, which sometimes may require specific PHP versions. With FastComet, all shared hosting clients can set specific PHP versions for different directories. For example, if you want to run PHP 7.4 on your account, but you have to set PHP 7.2 because of your specific application requirements, you can do that by setting custom rules for each of your folders. In this post, we will explain how to run multiple PHP versions on the very same account.

How to Change the PHP Version for your Account

By default, all our Shared Hosting servers run PHP 7.2 as the native PHP version. With time, scripts may discontinue supporting this version of PHP, and thus clients need to have the option to run a newer PHP version on their accounts. If you just want to change the version of PHP site-wide you can follow the steps of our step-by-step tutorial.

Choosing a PHP Version for a Specific Directory

You can use any combination of different PHP versions running simultaneously in any directory on the account. While this is not available using the PHP Selector UI, it is fairly simple to do manually.

To set a different PHP version from the one assigned to your domain on your cPanel account, you need to add a special code to your .htaccess file. The .htaccess file is a hidden file that is read by the webserver. The web server follows any instructions contained within the file. For the purposes of this article, we will explain accessing it through the File Manager on the cPanel of your hosting account.

Navigate to the section Files → File Manager. If you wish to edit .htaccess file for your main domain, navigate to the public_html folder. In case you need to make some changes to an addon domain, go to public_html/youraddondomain.com folder.

Once you are in the File Manager, make sure that you have "Show hidden files" enabled:

This way, you will be able to see "dot" files, which are usually hidden by default. The specific file you need in that case is the .htaccess file.

To set a custom PHP version for your desired directory, either select the .htaccess file and click on Edit from the toolbar, or right-click over it and choose the option to Edit the file:

A pop-up window will appear, where once again you need to click on Edit:

Available PHP Handlers

Now that you are inside the .htaccess file, аt the top of the file, insert the PHP handler for the version you would like to use. If there is a handler in the file already, it should be removed or replaced with your new handler. Depending on your desired PHP version for your specific application (folder), add one of the following lines:

For PHP 5.6:

AddHandler application/x-httpd-php56 .php .php5

For PHP 7.0:

AddHandler application/x-httpd-php70 .php .php5

For PHP 7.1:

AddHandler application/x-httpd-php71 .php .php5

For PHP 7.2:

AddHandler application/x-httpd-php72 .php .php5

For PHP 7.3:

AddHandler application/x-httpd-php73 .php .php5

For PHP 7.4:

AddHandler application/x-httpd-php74 .php .php5

For PHP 8.0:

AddHandler application/x-httpd-php80 .php .php5

For PHP 8.1:

AddHandler application/x-httpd-php81 .php .php5

The actual change is made by switching the SetHandler line with one of these depending on the version (look at the last two digits):

  • SetHandler application/x-lsphp56
  • SetHandler application/x-lsphp70
  • SetHandler application/x-lsphp71
  • SetHandler application/x-lsphp72
  • SetHandler application/x-lsphp73
  • SetHandler application/x-lsphp74
  • SetHandler application/x-lsphp80
  • SetHandler application/x-lsphp81

After you have added your own configuration rules, save your changes and close the .htaccess file. Now you should have your custom PHP version set.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to transfer your website to FastComet hosting plans

A free website transfer is provided for all FastComet clients. Our technical support team will...

Do Website Transfers Affect SEO?

It's a well-known fact that Search Engine Optimization (SEO) is crucial for increasing the...

How to Transfer Existing Website from BlueHost

We would be glad to assist you with the transfer of your website, which is something that we...

How to Use an SSL Certificate from another Company with your FastComet Account

Yes, you can have SSL purchased via another hosting company installed on your hosting account...

How to Transfer Your Website from LunarPages to FastComet

We will gladly assist you with the transfer of your website which is included as a free service...