How To Set Custom PHP Version Per Directory? Print

  • 0

On CloudLinux shared hosting plans, we support multiple PHP versions. You can determine which PHP version you want to run in a folder or domain by defining a rule in the .htaccess file. Using the file manager or an FTP client, you can create/edit a .htaccess file.

Steps to change a PHP Version for a Specific Directory.

You can set a different PHP version from the one assigned to your domain on your cPanel account by adding a special code to a hidden file known as .htaccess. The .htaccess file is read by the web server, which follows any instructions contained within it. To access the .htaccess file through File Manager on the cPanel account, follow these steps:

1) To access the .htaccess files for your main domain, navigate to the folder public_html. To access configuration files for an addon domain, navigate to the folder public_html/youraddondomain.com. If you don’t know the path of your website, you can verify or check it from the Domains section in cPanel. When you are in the File Manager, ensure that you have "Show hidden files" enable:


2) Select the .htaccess file and click on Edit from the toolbar to set a custom PHP version for your desired directory.

3) Now add the rule into your .htaccess file at the beginning of it, as mentioned in the below table. 

PHP Version Code
PHP version 7.0: AddHandler application/x-httpd-php70 .php .php5
PHP version 7.1: AddHandler application/x-httpd-php71 .php .php5
PHP version 7.2: AddHandler application/x-httpd-php72 .php .php5
PHP version 7.3: AddHandler application/x-httpd-php73 .php .php5
PHP version 7.4:  AddHandler application/x-httpd-php74 .php .php5
PHP version 8.0: AddHandler application/x-httpd-php80 .php .php5
PHP version 8.1: AddHandler application/x-httpd-php81 .php .php5

4) Save the .htaccess file.

That's it.


Was this answer helpful?

« Back

chat