How to Use a Specific PHP Version in a cPanel Folder

How to Use a Specific PHP Version in a cPanel Folder

When you have more than one website in cPanel, you might need a different PHP version for each site, requiring you to use a specific PHP version in different folders. But what if the folder you created is inside public_html?

Naturally, the PHP version will follow the one applied to the main domain on the hosting (except for subdomains and addon domains, which can have their versions changed from the MultiPHP Manager page).

If you want to do this, you can follow the tutorial below to use a specific PHP version in a cPanel.

1. Check the PHP Version Being Used

The first step you need to take is to check the PHP version used in your folder. You can create a PHP file, for example info.php, and add the following code to check the PHP version.

<?phpphpinfo();?>

After adding that file, you can try accessing the info.php page on your website, for example wpgan.com/info.php, and the result will look like this.

Next, for this example, we will use the /phpcustom/ folder to use a different PHP version, so you can create the same file inside the /phpcustom/ folder to check the PHP version.

From the results above, the folder will naturally use the same PHP version, which is version 8.1. Therefore, we will make the /phpcustom/ folder use PHP version 7.4, for example.

2. Create an .htaccess File

To use a different PHP version, you need to create an .htaccess file inside the folder you are going to use (if there is no .htaccess file there yet).

To add an .htaccess file, you can click on + File located inside the cPanel File Manager, then for the file name, enter .htaccess (make sure there is a dot at the beginning)

3. Add a PHP Handler

This step is the most important one for changing the PHP version in the folder you are using.

First, you need to edit the .htaccess file you created by right-clicking on the .htaccess file and then selecting the edit option.

Inside the .htaccess file, add a handler to specify the PHP version. Since we are going to use PHP 7.4 here, the code that needs to be added looks like this.

<IfModule mime_module>  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml</IfModule>

Save the code and make sure you have written it correctly. If you want to change it to another version, for example PHP 5.6, you can change x-httpd-ea-php74 to x-httpd-ea-php56 or x-httpd-alt-php56 and change php7 to php5

4. Check the PHP Version

Since you have now adjusted the handler in the /phpcustom/ folder, you can check the PHP version check page again and compare it with the PHP version on the main domain. The result will look like this.

And when you check the main page or folder, the PHP version used remains unchanged.

That is an easy way to use a specific PHP version in a cPanelfolder. If you want to use a different PHP version and are confused about how to change the handler, you can copy one of the following handlers.

5. List of PHP Handlers

The following list of handlers only includes commonly used PHP handlers such as PHP 5.6, 7.2, 7.3, 7.4, and so on, and uses the EA version, not ALT.

PHP 5.6

<IfModule mime_module>  AddHandler application/x-httpd-ea-php56 .php .php5 .phtml</IfModule>

PHP 7.2

<IfModule mime_module>  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml</IfModule>

PHP 7.3

<IfModule mime_module>  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml</IfModule>

PHP 7.4

<IfModule mime_module>  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml</IfModule>

PHP 8.0

<IfModule mime_module>  AddHandler application/x-httpd-ea-php80 .php .php8 .phtml</IfModule>

PHP 8.1

<IfModule mime_module>  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml</IfModule>

PHP 8.2

<IfModule mime_module>  AddHandler application/x-httpd-ea-php82 .php .php8 .phtml</IfModule>

PHP 8.3

<IfModule mime_module>  AddHandler application/x-httpd-ea-php83 .php .php8 .phtml</IfModule>

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...