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

  1. Log in to cPanel.
  2. Open File Manager and navigate to the directory where you want to apply a specific PHP version.
  3. Locate the .htaccess file. If it doesn’t exist, create a new file named .htaccess.
  4. 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

  1. Create a phpinfo.php file in each directory with the following content:

<?php phpinfo(); ?>

  1. Visit the file in your browser (e.g., https://yourdomain.com/phpinfo.php and https://yourdomain.com/app/phpinfo.php).
  2. Verify that the PHP version matches what you set in the .htaccess file.

Was this article useful and on point?

Find out more about MonsterMegs entire range of optimized Web Hosting Services and take action today on improving your website Loading Speed, Security, and overall Stability!
Was this answer helpful? 1 Users Found This Useful (1 Votes)