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 Inkhost, 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

Keep in mind that those lines are only for FastCloud and FastCloud Plus clients. If you are using our FastCloud Extra plan, your addition to the .htaccess file needs to be a bit different.

For customers using our FastCloud Extra 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 (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

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.

If you have difficulty with the PHP settings of your hosting account, do not hesitate to contact the Inkhost technical support team.

هل كانت المقالة مفيدة ؟

مقالات مشابهة

How to Make All .html Pages to Run as .php Files Using .htaccess

PHP can be extremely useful when used in conjunction with HTML to enhance the features of a...

How to change PHP timezone for your website

If you have noticed that the correct time is not displaying in your PHP scripts it is because...

How to change my PHP version

We are glad to inform you that you can change the current version of PHP even on shared hosting...

How to change the max memory and max upload limit

Changing of PHP variables is easy on our shared hosting plans. You have full control and you...

Why is phpinfo() Disabled and How to Enable It

The phpinfo() function shows information about server settings and the Kernel version. Such...

Powered by WHMCompleteSolution