Advanced Apache Configuration

Last modified: September 4, 2024


Overview

EasyApache 4 provides several ways for you to customize your Apache configuration.

Important:
  • Make certain that you only use the methods below to modify your Apache configuration. If you use a method that we do not support, cPanel & WHM and EasyApache 4 can overwrite your custom configuration.
  • We strongly recommend that you read Apache’s Configuration Files documentation before you customize your Apache configuration.

How it works

EasyApache 4 builds your global Apache configuration from the following components:

  • The modules, options, and extensions that EasyApache 4 installs for Apache.
  • Global configuration templates in the /var/cpanel/templates/apache2_4/ directory.

EasyApache builds each virtualhost tag from the following components:

  • Any custom templates in the /var/cpanel/templates/apache2_4/ directory.
  • The content of the /etc/apache2/conf.d/userdata/ directory. This includes account information and domain-specific templates.

Modify the Apache configuration options

htaccess files

When Apache processes a file request, it searches for an .htaccess configuration file inside the file’s directory. If a .htaccess file exists for the directory, and Apache can read it, Apache uses the .htaccess file to modify the requested file’s configuration. For more information about how to use .htaccess files, read Apache’s HTTP Server Tutorial.

Some events in the cPanel & WHM environment trigger an .htaccess syntax check, which will skip loading modules. To avoid errors from these modules, wrap any directives that come from them in an <IfModules></IfModule> block, as displayed in the following example:

1
2
3
<IfModule mod_suphp.c>
    suPHP_ConfigPath /etc
</IfModule>

PHP-FPM

On servers that run PHP-FPM, in order to use the ErrorDocument directive, you must set the ProxyErrorOverride directive to On for your specific virtual host.

Important:
  • A server that enables the ProxyErrorOverride directive will display different error behavior than servers that do not run PHP-FPM and those that do not enable the directive.
  • We strongly recommend that you do not set the ProxyErrorOverride directive to On in a global include file. This may cause unexpected behavior.
For more information about PHP-FPM, read our PHP-FPM documentation.

Modify global Apache configuration

To modify your global Apache configuration, use one or more of the following methods:

Modify Apache configuration directives via WHM

Use WHM’s Global Configuration interface (WHM » Home » Service Configuration » Apache Configuration » Global Configuration) to modify global default Apache configuration directives.

Modify Apache configuration files via WHM

Use WHM’s Include Editor interface (WHM » Home » Service Configuration » Apache Configuration » Include Editor) to modify global or specific Apache configuration directives via include files.

Modify Apache configuration via the command line with new conf files

To modify the Apache configuration via the command line, create custom configuration files in the /etc/apache2/conf.d/ directory. Your new configuration files must meet the following requirements:

  • Use the .conf file extension.
  • Possess root:root ownership.
  • Use 0600 permissions.

After you modify a .conf file, including by adding or removing the file, you must restart the Apache service with the service httpd restart command.

Modify the content of specific virtual hosts via the command line

You can use the command line to add include files that modify the content of the virtual host containers in your Apache configuration. You may wish to do this to modify the configuration of an individual domain or a specific user’s domains.

For more information about how to modify your virtual host containers with include files via the command line, read our Modify Apache Virtual Hosts with Include Files documentation.

Additional Documentation