How to Set a Different PHP Version for an Addon Domain
SternHost utilizes CloudLinux as the operating system on its servers, providing enhanced stability and security for hosted websites. One of the most beneficial features of CloudLinux is the ability for users to select the PHP version that best suits their website’s needs. This flexibility is essential when running applications that require a specific PHP version to function properly.
However, a common limitation within cPanel is that it does not offer an option to assign different PHP versions directly to addon or subdomains. Despite this restriction, you can still configure distinct PHP versions for addon domains, subdomains, or even specific directories by modifying the `.htaccess` file associated with your website.
To customize the PHP version for an addon domain or directory, you must add PHP handlers to the `.htaccess` file. These handlers instruct the server to use a specified version of PHP for the content served in that directory.
List of handlers for different PHP versions:
PHP 5.6:
`AddHandler application/x-httpd-alt-php56 .php .php7 .phtml`
PHP 7.0:
`AddHandler application/x-httpd-alt-php70 .php .php7 .phtml`
PHP 7.1:
`AddHandler application/x-httpd-alt-php71 .php .php7 .phtml`
PHP 7.2:
`AddHandler application/x-httpd-alt-php72 .php .php7 .phtml`
PHP 7.3:
`AddHandler application/x-httpd-alt-php73 .php .php7 .phtml`
PHP 7.4:
`AddHandler application/x-httpd-alt-php74 .php .php7 .phtml`
PHP 8.0:
`AddHandler application/x-httpd-alt-php80 .php .php8 .phtml`
PHP 8.1:
`AddHandler application/x-httpd-alt-php81 .php .php8 .phtml`
PHP 8.2:
`AddHandler application/x-httpd-alt-php82 .php .php8 .phtml`
PHP 8.3:
`AddHandler application/x-httpd-alt-php83 .php .php8 .phtml`
Setting a Global PHP Version
If you prefer to apply a global PHP version for all domains under your cPanel account, this can be achieved using the “Select PHP Version” tool within cPanel. This setting affects all domains and subdomains associated with your account. However, this global setting does not restrict you from assigning a different PHP version to individual addon domains or directories using the method outlined above.
How to Set PHP 5.6 for an Addon Domain
To configure PHP 5.6 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
Once this is done, the addon domain will use PHP 5.6 instead of the global version configured in cPanel.
How to Set PHP 7 for an Addon Domain
To assign PHP 7 to an addon domain, edit the .htaccess file in the relevant directory and add the following code:
# 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
This ensures that the addon domain will use PHP 7 rather than the account’s default PHP version.
How to Set PHP 7.1 for an Addon Domain
To configure PHP 7.1 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
This will configure PHP 7.1 for that specific addon domain.
How to Set PHP 7.2 for an Addon Domain
To configure PHP 7.2 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
How to Set PHP 7.3 for an Addon Domain
To configure PHP 7.3 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
How to Set PHP 7.4 for an Addon Domain
To configure PHP 7.4 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
How to Set PHP 8.0 for an Addon Domain
To configure PHP 8.0 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
How to Set PHP 8.1 for an Addon Domain
To configure PHP 8.1 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
How to Set PHP 8.2 for an Addon Domain
To configure PHP 8.2 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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-php82 .php .php8 .phtml
# php -- END cPanel-generated handler, do not edit
How to Set PHP 8.3 for an Addon Domain
To configure PHP 8.3 for a specific addon domain, create or modify the .htaccess file in the directory where the addon domain is located. Add 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
By following these steps, you can set different PHP versions for addon domains or specific folders without affecting the global PHP settings in cPanel.