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.
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.
Thanks Karl, exactly what I was looking for.
Thanks so much, u saved me alot of time
Pingback: cPanel, PHP set_include_path Function & Apache php_admin_value | Website Factors
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
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.
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.