If you want to run multiple PHP versions within the same cPanel account, CloudLinux PHP Selector allows you to set a different PHP version for each directory using .htaccess
rules. This can be useful if you have multiple applications or scripts that require different versions of PHP.
Step 1: Identify the PHP Version You Want to Use
CloudLinux provides several PHP versions. Use the appropriate handler for the version you want:
- PHP 5.6:
application/x-lsphp56
- PHP 7.4:
application/x-lsphp74
- PHP 8.0:
application/x-lsphp80
- PHP 8.1:
application/x-lsphp81
- PHP 8.2:
application/x-lsphp82
Step 2: Create or Edit the .htaccess
File
- Log in to cPanel.
- Open File Manager and navigate to the directory where you want to apply a specific PHP version.
- Locate the
.htaccess
file. If it doesn’t exist, create a new file named.htaccess
. - Edit the file and add the following code to set the desired PHP version:
<FilesMatch "\.php$">
SetHandler application/x-lsphp74
</FilesMatch>
Step 3: Apply a Different PHP Version to a Subdirectory
To use a different PHP version in a subdirectory, create a .htaccess
file in that subdirectory with a different SetHandler
value.
Example:
- Root Directory (
public_html
) – Use PHP 7.4:
<FilesMatch "\.php$">
SetHandler application/x-lsphp74
</FilesMatch>
- Subdirectory (
public_html/app
) – Use PHP 8.1:
<FilesMatch "\.php$">
SetHandler application/x-lsphp81
</FilesMatch>
Step 4: Test Your Setup
- Create a
phpinfo.php
file in each directory with the following content:
phpinfo();
- Visit the file in your browser (e.g.,
https://yourdomain.com/phpinfo.php
andhttps://yourdomain.com/app/phpinfo.php
). - Verify that the PHP version matches what you set in the
.htaccess
file.