How to Set Custom PHP Version per Directory

Updated on Jun 27, 2019

After the recent upgrade on all FastComet Shared Hosting servers customers are able to change their PHP versions per directory base.

For example, if you would like to have two different applications installed, which require different PHP versions you can easily achieve this by setting custom rules for each folder.

Let say you would like to run PHP 5.4 for your account but you would like to install ClipBucket, which requires PHP 5.3. To achieve this, log in to your cPanel and refer to the Select PHP version icon under the Software and Services section.

Select the desired global version for your account and click on the "Set as Current" button.

To set a different PHP version for a subfolder under your account go to your cPanel File Manager. Make sure you have the option "Show hidden files" selected as we will need to edit a hidden file called .htaccess.

Navigate to the desired subfolder and locate the .htaccess file.

From the popup window, click Edit to open the .htaccess file for editing.

Depending on the PHP version you would like to apply add the one of the following lines at the top of the file (this is valid for StartSmart and ScaleRight plans):

For PHP 5.3:

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

For PHP 5.4:

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

For PHP 5.5:

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

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

Now the desired PHP version should be enabled for your directory.

For customers using our SpeedUp packages, please use the following snippet in your .htaccess file:

<FilesMatch ".(php4|php5|php3|php2|php|phtml)$">
SetHandler application/x-lsphp<phpversion>
</FilesMatch>

The actual change is made by switching the SetHandler line with one of these depending on the version:

For PHP 5.3:

SetHandler application/x-lsphp53

For PHP 5.4:

SetHandler application/x-lsphp54

For PHP 5.5:

SetHandler application/x-lsphp55

For PHP 5.6:

SetHandler application/x-lsphp56

For PHP 7.0:

SetHandler application/x-lsphp70

For PHP 7.1:

SetHandler application/x-lsphp71

For PHP 7.2:

SetHandler application/x-lsphp72

For PHP 7.3:

SetHandler application/x-lsphp73

We hope you find this article useful. Discover more about FastCloud - the top-rated Hosting Solutions for personal and small business websites in four consecutive years by the HostAdvice Community!

SSD Cloud Hosting

  • Free Domain Transfer
  • 24/7 Technical Support
  • Fast SSD Storage
  • Hack-free Protection
  • Free Script Installation
  • Free Website Transfer
  • Free Cloudflare CDN
  • Immediate Activation
View More