Editing Virtualhost Settings in WHM / cPanel

If you are using WHM and you try to edit your Virtualhost settings in your httpd.conf, you will find the following warning message:

1
# DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.

This is not the most helpful warning message. Your first thought is probably that “the include files” refers to the pre_main, pre_virtualhost and post_virtualhost includes, but obviously they are no use when you are trying to edit the Virtualhost settings themselves.

Looking a bit closer inside the Virtualhost blocks in httpd.conf, the following advice is uncovered:

1
2
# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/username/domain.com/*.conf"

This helps a bit, but it’s still not especially clear what you need to do. For one thing this file doesn’t exist, and even if you create it the Include line is commented – and the whole point of this exercise is that the http.conf file cannot be manually edited so you can’t just uncomment it!

For anyone with this problem, hopefully the following should explain the full process needed.

First create the file mentioned inside the Virtualhost block. Note that this will be dependent on your username and domain so don’t just copy and paste the path below!

1
mkdir -p /usr/local/apache/conf/userdata/std/2/username/domain.com

Navigate to the directory you just created:

1
cd /usr/local/apache/conf/userdata/std/2/username/domain.com

Create a configuration file using your editor of choice (filename must end in .conf), and add any settings you need:

1
nano extra.conf

Now to uncomment the include, run the following command:

1
/scripts/ensure_vhost_includes --all-users

This script will uncomment any Include lines in httpd.conf Virtualhost blocks where it finds at least one *.conf file in the relevant directory. It will restart Apache for you so no need to do that – your changes should be immediate.

16 comments

  • CrazyCharlie

    Any way to overwrite or change a directive within the VirtualHost using this method? For example, drop a URL from the ServerAlias directive? I tried adding the corrected ServerAlias line in my custom config file and it didn’t change the directive and likely just added to it.

    Thanks.

  • Jacob

    Thanks Karl, exactly what I was looking for.

  • Omar Abdallah

    Thanks so much, u saved me alot of time

  • Pingback: cPanel, PHP set_include_path Function & Apache php_admin_value | Website Factors

  • Tihomir

    Oh man… how were we supposed to know about ensure_vhost_includes script? Thanks, this was a huge time saver!

  • Pingback: httpd.conf y Cpanel: Cómo personalizar la configuración

  • Shane

    Where in WHM are you creating the file and executing those commands? I can’t see where in WHM/cpanel that lets you do that. thank you.

  • Ryan

    Thanks for this. Seems like the important part of telling WHM to include the includes was getting left out of all the other tutorials I found. The call to ensure_vhost_includes solved much frustration.

  • jake

    awesome. this worked perfectly.

  • Pingback: mod rewrite and forward slashes | Cron Systems Corp.

  • Pingback: mod_fcgid: HTTP request length XXX (so far) exceeds MaxRequestLen (XXX) | Cron Systems Corp.

  • Erik Evenson
  • Silver Moon

    I have a vps server and host multiple domains on it , using cpanel and whm. I need to use mpm-itk , and it requires an entry in virtual hosts section for each domain to specify the user id. So can I use separate vhost files (as shown in your post) to create the mpm-itk entries for assigning username ?

    What I will do it , create an account in whm , then create the extra.conf from shell , and then write the mpmitk directive in it. Is that a good idea ?

    Regards
    Silver

  • kewlceo

    Thanks Karl, I’ve always wanted to understand the convoluted includes system and you’ve finally demystified it for me.

  • Pingback: httpd.conf y Cpanel/whm: virtual hosts y configuración personalizada | Dave's Site

  • Reydel Leon

    Thnaks very much! It works as expected, and cleared up my mind in some aspects regarding apache in shared hosts that I didn’t know.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>