View Categories

How to set a different PHP version for a specific folder

This guide teaches you how to use a different PHP version only for a specific folder, different from the one set at the account level in cPanel > Select PHP Version.

This feature is useful if an application in a subfolder requires a specific PHP version, different from the rest of the site.

1. Check available PHP versions

Go to the Select PHP Version section in cPanel and make sure the desired version (e.g., PHP 8.1) is active for your account.

2. Create/edit a .htaccess file in the folder where you want the different PHP version

Open or create a .htaccess file in the desired folder and add the following line:

<FilesMatch "\.(php4|php5|php3|php2|php|phtml)$">
    SetHandler application/x-httpd-alt-php81___lsphp
</FilesMatch>

This example sets PHP 8.1 only for .php files in that folder.

For other PHP versions, replace php81 with the desired version code:

PHP Version | Code for .htaccess

PHP 5.6 application/x-httpd-alt-php56___lsphp
PHP 7.4 application/x-httpd-alt-php74___lsphp
PHP 8.0 application/x-httpd-alt-php80___lsphp
PHP 8.1 application/x-httpd-alt-php81___lsphp
PHP 8.2 application/x-httpd-alt-php82___lsphp
PHP 8.3 application/x-httpd-alt-php83___lsphp
PHP 8.4 application/x-httpd-alt-php84___lsphp
PHP 8.5 application/x-httpd-alt-php85___lsphp