PHP Inheritance


Last modified: October 30, 2023

Overview

In WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager), the term “Inherit” refers to how Apache determines a domain or virtual host’s PHP version.

When you set a cPanel account or domain to use the Inherit option, Apache uses the PHP version that exists in the first .htaccess file that it finds in the domain’s file structure. If the system cannot find an .htaccess file, Apache uses the system default PHP version. The system sets the PHP version of each new domain to the default value.

Important:

The system enables PHP-FPM by default. You cannot set a cPanel account’s PHP version to use the Inherit option with PHP-FPM enabled.

How inheritance works

PHP inheritance follows the following path:

  1. You set the PHP version at the system level.

    Important:

    We strongly recommend that you only set the PHP version in WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager). If you set your PHP version manually, you may experience unexpected behavior.

  2. You set a cPanel account or domain to use the Inherit option in WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).

  3. Apache searches the cPanel & WHM default document root of the current domain and continues up the directory tree until it finds an .htaccess file with PHP version information.

    Important:
    • The document root location determines how your domain inherits its PHP version. For example, if a domain’s document root is underneath a subdomain, the domain will inherit the subdomain’s PHP version.
    • For a primary domain, the default document root is the /$HOME/user/public_html directory.
    • For a subdomain or addon domain, the default document root depends on your server’s settings. For more information, read our Tweak Settings documentation.
    • When you set a domain’s PHP version, the system creates its .htaccess file.

  4. Apache locates an .htaccess file with PHP version information.

  5. Each cPanel account or domain set to Inherit now uses the PHP version in the .htaccess file.

    Note:
    • If Apache does not find an .htaccess file, it uses the system default PHP version from WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).
    • If Apache finds an invalid version of PHP in the .htaccess file, it uses the system default PHP version set in WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).

Example

In the following table, the system uses PHP 8.2 by default:

Note:

In the following table, the sub3.example.com and sub4.example.com domain examples are only valid if you set the Restrict document roots to public_html option in WHM’s Tweak Setting interface (WHM » Home » Server Configuration » Tweak Settings) to Off.

Domain Domain type PHP setting Effective PHP version Document root within the /public_html directory
example.com Primary 8.0 8.0 Yes
addon-example.com Addon Inherit 8.2 Yes
sub1.example.com Subdomain 8.3 8.3 Yes
sub2.example.com Subdomain Inherit 8.3
Note:
In this example, the sub2.example.com subdomain’s document root is underneath the sub1.example.com subdomain. Therefore, sub2.example.com will inherit its PHP version from sub1.example.com.
Yes
sub3.example.com Subdomain Inherit 8.2 No
sub4.example.com Subdomain 8.2 8.2 No
domain.com Primary Inherit 8.2 Yes
sub5.domain.com Subdomain Inherit 8.2 Yes
sub6.domain.com Subdomain 8.0 8.0 Yes
addon-example2.com Addon Inherit 8.2 No

Additional Documentation