How to Set a Different PHP Version for an Addon Domain? Print

  • 1

At DreamWebHosts, we use CloudLinux OS on all our servers to ensure enhanced performance, security, and stability for every hosting account. One of the key benefits of CloudLinux is the ability to select your preferred PHP version based on your website or application requirements.

This feature is especially useful if your website depends on a specific PHP version for compatibility or performance optimization.

Important Limitation in cPanel

While CloudLinux allows you to easily change the PHP version for your main domain via cPanel, it does come with a limitation:

- You cannot assign different PHP versions to Addon Domains or Subdomains directly through cPanel.

Workaround: Use .htaccess for Custom PHP Versions

Even though this option is not available in cPanel, you can still configure different PHP versions for:

- Addon Domains
- Subdomains
- Specific folders or directories

This can be achieved by using PHP handlers within your website’s .htaccess file.

By placing the appropriate handler in the desired directory, you can override the default PHP version and run a different version as needed.

Available PHP Handlers

You can switch between PHP versions by adding the corresponding handler in your .htaccess file. Below are the supported PHP handlers:

AddHandler application/x-httpd-alt-php56 .php .php7 .phtml
AddHandler application/x-httpd-alt-php70 .php .php7 .phtml
AddHandler application/x-httpd-alt-php71 .php .php7 .phtml
AddHandler application/x-httpd-alt-php72 .php .php7 .phtml
AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
AddHandler application/x-httpd-alt-php74 .php .php7 .phtml
AddHandler application/x-httpd-alt-php80 .php .php8 .phtml
AddHandler application/x-httpd-alt-php81 .php .php8 .phtml
AddHandler application/x-httpd-alt-php82 .php .php8 .phtml
AddHandler application/x-httpd-alt-php83 .php .php8 .phtml
AddHandler application/x-httpd-alt-php84 .php .php8 .phtml

How to Set PHP 5.6 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 5.6 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php56” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php56 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 5.6 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 7 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 7 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php70” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php70 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 7 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 7.1 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 7.1 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php71” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php71 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 7.1 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 7.2 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 7.1 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php72” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php72 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 7.2 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 7.3 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 7.3 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php73” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php73 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 7.3 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 7.4 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 7.4 version for one of your Addon Domains.

Create a .htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php74” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php74 .php .php7 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 7.4 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 8.0 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 8.0 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php80” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php80 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 8.0 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 8.1 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 8.1 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php81” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php81 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 8.1 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 8.2 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 8.2 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php82” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php81 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 8.1 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 8.3 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 8.3 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php83” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php83 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 8.3 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

How to Set PHP 8.4 Version for an Addon Domain

Let’s have a practical example of how to set the PHP 8.4 version for one of your Addon Domains.

.htaccess file in the desired directory or modify an existing .htaccess file where you want to have a different from default PHP version with the following handler:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php83” package as the default “PHP” programming language.
AddHandler application/x-httpd-alt-php84 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit

As a result, an addon domain, for instance, will use the PHP 8.4 version which you’ve set for it, and not the global one set for the account in the cPanel > PHP Selector.

That’s a wrap!

Now you know how you can easily change the PHP version on your Addon domains by using one of the following handlers, according to your desired PHP version.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution