How To Set Custom PHP Version For Different Directory?

On our Linux shared hosting plans, we have Cloudlinux, which supports 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. These allows you to set custom PHP version for differet directory.

Below are the 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 code to a hidden file known as .htaccess. The .htaccess file is read by the web server, which follows any instructions written in the file. To access the .htaccess file through File Manager on the cPanel account, follow the below steps:

  1. Login into your cPanel Account.
  2. In Files section, click on File Manager.
    cpanel file manager
  3. 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 do not 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.
    show hidden files cpanel
  4. Select the .htaccess file and click Edit from the toolbar to set a custom PHP version for your desired directory.
    edit htaccess to set custom php version
  5. 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
  6. Save the .htaccess file.
    add handler and save htaccess file

Thats It! You can follow above steps and set custom PHP version for different directories.

Add a Comment

Your email address will not be published. Required fields are marked *