Jan 4, 2012
tom

How do I overwrite rather than modify a virtualhost on WHM/Cpanel?

Question

I’m trying to completely replace the current virtual host autogenerated in httpd.conf with the following (its for a ruby app). I put this in extra.conf at the location that httpd.conf specifies for each virtual host block (its something like userdata/std/2/username/site.org/*.conf:

<VirtualHost *:80>
    ServerName www.site.org
    DocumentRoot /home/why/app/public
    <Directory /home/why/app/public>
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>

I say ‘overwrite’ because when i run /scripts/ensure_vhost_includes --all-users it tells me that <VirtualHost> cannot occur within <VirtualHost> section. Obivously that means I need to reformat the virtualhost, but I am new to apache and I just want it to use what i’m including rather than trying to ‘integrate’ it with the current virtualhost. My knowledge isnt good enough to know if its doing it right, so I’d like to use exactly what I’m given from Phusion Passenger (a deployment apache module): http://www.modrails.com/documentation/Users%20guide%20Apache.html

Answer

If you add your virtual’s full config as a “Pre VirtualHost Include“, it will override the corresponding auto-generated config.

To do this, go to the “Apache Configuration” section of the Service Configuration area, and select the Include Editor. The “Pre VirtualHost Include” section is there.

Be sure to replicate all of the auto-generated configuration options that you want to keep, of course! You said that you wanted to just follow that particular recipe, but I’d take a few moments to make sure that you’re not leaving out something that’s a good idea for your particular hosting setup, etc.

Related posts:

  1. cPanel WHM virtualhost sample
  2. How to stick my changes in httpd.conf on WHM/Cpanel/EasyApache
  3. WHM – Content served over https only, http throws 404
  4. Virtualhost cannot occur withing VirtualHost section
  5. Use server ip instead of domain? Cpanel / WHM

Leave a comment