PHP is among the most widely used web programming languages. And just like other popular programming languages, it has multiple versions. And selecting the right version is a crucial task in itself. Certain applications may demand the use of specific PHP version. So you may want to set a specific PHP version for each directory.
In this article, we explain how to set custom PHP version for each directory. For example, your account might be running on PHP 7.4. But if you want to use PHP 7.2 for a specific application, you can make changes to custom rules application for the folders. This way, you can use multiple PHP versions in one account.
Setting Custom PHP Version to a Directory
Within an account, you’re free to use any combination of PHP versions. It’s not available in the PHP Selector UI. So you need to do it manually.
To get started, you’d need to log into your cPanel account. And then you’d have to add some code to the .htaccess file.
Here are the steps involved:
Now you’ve set the custom PHP version appropriately. If you face any issues, contact your hosting provider support team.
In this article, we explain how to set custom PHP version for each directory. For example, your account might be running on PHP 7.4. But if you want to use PHP 7.2 for a specific application, you can make changes to custom rules application for the folders. This way, you can use multiple PHP versions in one account.
Setting Custom PHP Version to a Directory
Within an account, you’re free to use any combination of PHP versions. It’s not available in the PHP Selector UI. So you need to do it manually.
To get started, you’d need to log into your cPanel account. And then you’d have to add some code to the .htaccess file.
Here are the steps involved:
- Log into your cPanel with required credentials
- Open Files Manager under the Files section
- If you’re hosting multiple websites, select the website you want to work on
- From the left-hand side panel, open the public_html folder
- Once you’re inside, click on “Settings” and enable “Show Hidden Files” box. This will display the .htaccess file, which by default, stays hidden
- Right-click on the .htaccess file and click on “Edit”
- At the top of the file, you have to insert the PHP handler. Copy and paste the following handler:
Code:
AddHandler application/x-httpd-phpV .php .php5
- Replace “V” with the version of PHP you want to set. So for PHP 7.1, here’s how the Handler would look:
Code:
AddHandler application/x-httpd-php71 .php .php5
- Make sure there’s no “.”(dot) in between the 7.1
- Save the file and exit.
Now you’ve set the custom PHP version appropriately. If you face any issues, contact your hosting provider support team.