PHP Version for a Specific Directory
Authorization
Site Sections
Downloads News Blogs Guestbook Music Photos Videos Communities Users Forum Games
© geopak.mobi - 2023

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


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
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.

Subsection: Discussions
Section: Web Masters

Topic Files
Last edited REHAN - 16 Mar 2023, 22:10
Latest Activity: 16 Mar 2023, 22:10
Comments 0
No comments yet
Sorry, comments are not available for you
Back
Advertisement

Best and Cheap SSD Hosting
Use our refer link and get Discount