Modify Apache Virtual Hosts with Include Files
Last modified: 2024 September 4
Overview
You can use the command line interface to add include files that modify the content of the virtual hosts in your Apache configuration. You may wish to do this to modify the configuration of an individual domain, or a specific user’s domains.
You must create the directories and the include files for this type of configuration. For information on the directives that you can add to the virtual hosts in your Apache configuration, read Apache’s documentation.
- Includes are the last directives in each virtual host. An include file’s contents override any value that exists in the primary configuration file.
- If you use an include that requires a specific Apache version, and you change to a different Apache version, the Apache configuration will ignore the include file.
Include file structure
You must use the following directory structure to create an include file for an individual domain:
In the following examples:
- Replace
userwith the account’s username. - Replace
domainwith the domain name. - Replace
includename.confwith the filename that you wish to include.
Apply to an individual virtual host
| Protocol | Include file |
|---|---|
| With SSL | /etc/apache2/conf.d/userdata/ssl/2_4/user/domain/includename.conf |
| Without SSL | /etc/apache2/conf.d/userdata/std/2_4/user/domain/includename.conf |
Apply to all virtual hosts on the system
- Include files that do not designate a specific Apache version may not migrate properly to future versions of Apache.
- Include files with local overrides cause the system to permanently disable the Force HTTPS Redirects option in cPanel’s Domains interface (cPanel » Home » Domains » Domains).
| Protocol | Include file |
|---|---|
| With SSL |
|
| Without SSL |
|
| With and without SSL | /etc/apache2/conf.d/userdata/includename.conf |
Apply to all virtual hosts that a user owns
| Protocol | Include file |
|---|---|
| With SSL | /etc/apache2/conf.d/userdata/ssl/2_4/user/includename.conf |
| Without SSL | /etc/apache2/conf.d/userdata/std/2_4/user/includename.conf |
Restart Apache
After you create or edit an Apache include userdata file, you must rebuild the httpd.conf file and restart Apache for the changes to take effect.
To rebuild the httpd.conf file, run the following script:
/usr/local/cpanel/scripts/rebuildhttpdconfTo restart Apache, run the following script:
/usr/local/cpanel/scripts/restartsrv_httpd