How to Use Apache Includes to Add Configuration Directives to a Specific Domain's VirtualHost


This article provides a guide for how to use Apache includes to add configuration directives to a specific domain's VirtualHost. This article explains how to add your custom directives to a single domain's VirtualHost, inside the VirtualHost context. This guide requires root level access to the cPanel VPS or cPanel Dedicated Server.

Apache configuration directives have certain contexts associated with them. The contexts that are associated with a directive determine where a directive can exist. For more information about Apache's Contexts, please see their documentation:

Contexts | Apache Documentation

There are some Apache directives that need to be set within the VirtualHost context. If you need to add a directive to the VirtualHost context, you would need to use the method described in this article to do so.

How to Use Apache Includes to Add Configuration Directives to a Specific Domain's VirtualHost

You'll need root access, either via SSH or the WHM Terminal to complete this task.

  1. as the root user, or log into WHM as root and navigate to Terminal.
  2. Issue the following commands, replacing CPANELUSERNAME and DOMAIN.TLD as appropriate for your situation. Additionally, the "include" in "include.conf" can be changed, but the files are loaded in alphabetical order. The username and domain portion are in all capital letters in this example to highlight what needs to be changed, but make sure to use all lowercase letters when running the commands on your server:
    mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/CPANELUSERNAME/DOMAIN.TLD/
    mkdir -p /etc/apache2/conf.d/userdata/std/2_4/CPANELUSERNAME/DOMAIN.TLD/
    touch /etc/apache2/conf.d/userdata/ssl/2_4/CPANELUSERNAME/DOMAIN.TLD/include.conf
    touch /etc/apache2/conf.d/userdata/std/2_4/CPANELUSERNAME/DOMAIN.TLD/include.conf
  3. Edit the newly created files so they contain your desired directives.
  4. Rebuild the Apache configuration to add the includes with this command:
    /usr/local/cpanel/scripts/rebuildhttpdconf
  5.  Restart Apache so it reads the new configuration:
    /usr/local/cpanel/scripts/restartsrv_httpd

Conclusion

You now know how to use Apache includes to add configuration directives to a specific domain's VirtualHost.

  • apache, apache directives, virtualhost, virtual hosts
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Remove a Service from ChkServd Monitoring for cPanel Servers

This guide requires root user account in server. In some circumstances, ChkservD cPanel...

Assigning a Dedicated IP Address to a Subdomain using WHM

To assign a dedicated IP address to a subdomain, perform the following steps: Step 1: Add the...

How to Fix Incorrect cPanel Account Quotas and Disk Usage

This article will provide a step-by-step guide to fix incorrect account quotas and disk usage on...

How to Uninstall Installatron in WHM cPanel Server

This guide will show you how to quickly uninstall Installatron software from WHM/cPanel server....

How to Install Installatron in WHM cPanel Server

This guide will show you how to download and install Installatron on your cPanel/WHM server. To...