httpd.conf for a single domain

gmpk

New Member
#1
Hello all,

I've just set up my first knownhost VPS with cPanel/WHM. I'm trying to figure out how to do things like edit the DocumentRoot for a single domain.

I notice a lot of weirdness in /usr/local/apache/conf/

Under /usr/local/apache/conf/sites/ I see mysite.com.conf and www.mysite.com.conf, are either of these what I should be looking at?

I'm just a little confused, I've never had to deal with whatever it is WHM/cPanel is doing with the httpd.conf files, I'd appriciate any help anyone could give.

Thanks,
Kyle
 

Dan

Moderator
#2
Hello Kyle :)

Normally you shouldn't edit the httpd.conf as cPanel takes care of it and edits you make there are overwritten when cPanel updates. There are other files indicated in it though that you can edit to add some things too. What is it you are trying to accomplish?
 

gmpk

New Member
#3
Hello Kyle :)

Normally you shouldn't edit the httpd.conf as cPanel takes care of it and edits you make there are overwritten when cPanel updates. There are other files indicated in it though that you can edit to add some things too. What is it you are trying to accomplish?
Hey, thanks for your reply.

At the moment I'm just trying to change the document root, enable mod_rewrite (if it isn't already), and try some things with mod_gzip. I really only want these things to affect the one domain, especially the changing of the document root.
 

Dan

Moderator
#4
Hi Kyle,

As far as changing the document root goes if you change it in the httpd.conf it is possible other things will break and I am certain it will be overwritten.

Can you do this with a redirect? In the cPanel for that domain you'll find the redirects applet which will create/modify the .htaccess for you.

If not then you MIGHT be able to overwrite the default document root by using one of the include files. My guess would be /usr/local/apache/conf/includes/post_virtualhost_2.conf would be the one you would want (I assume post_ as opposed to pre_ because you want to overwrite an existing variable defined). Again as a guess I would say you want to copy the whole virtualhost section for the domain in question into that file and modify the document root to where you want it. After doing this you will want to run /usr/local/cpanel/bin/apache_conf_distiller --update and then /usr/local/cpanel/bin/build_apache_conf to see if the changes 'stick' then restart apache and see if it worked.

Your configuration seems to be a bit different than mine since my /usr/local/apache/conf/sites directory is completely empty but files in there are most likely the same as what I see in my httpd.conf file in the virtualhost sections.

Mod_rewrite and mod_gzip you can install/enable globally using the EasyApache applet in WHM. I believe that mod_rewrite is installed by default but do not know about mod_gzip. Note that you will be recompiling apache here.

As a precaution if you do end up modifying any of cPanel's existing files make an 'oh sh*t' copy first hehehe been there done that!

Hope that helps
 

gmpk

New Member
#5
Thanks for the detailed reply, Dan. I turned out not doing what you said, but thanks for pointing me in the right general direction.

I noticed in the httpd.conf file it said this in the virtual host entry for the domain:

# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/mysite/mysite.com/*.conf"
So, I made that directory (mkdir -p /usr/local/apache/conf/userdata/std/2/mysite/mysite.com), and created a .conf file in there (nano config.conf). I put in the rules, did the rebuilding you mentioned, restarted Apache, and it worked like a charm. The "To customize this VirtualHost..." comment seems to vanish and the folder is included once it exists and you do the build_apache_conf stuff.
 
Top