Modification of Apache VirtualHost DocumentRoot?

mickoz

Member
Oct 24, 2006
7
0
151
Hi,

I need to migrate from a server (managed) to a cPanel server (which I will manage) about right now. And I am also quite new to cPanel (I understand it conceptually but in practice, I don't know what I can or not do under the hood without breaking it). I could test it and do more research, however after some research -- nothing that really tell me what I want to do won't break anything up. So here I go with my problem:

For our website to work, I would have to redefine the DocumentRoot set up by cPanel for the main-domain linked to my account.

I could do it myself, but I wonder if I will break anything doing so (e.g. cPanel might expect I do not modify anything it has generated in httpd.conf or anywhere else, so everything work well together – I imagine other cPanel options might get broken if I play with a setting cPanel manage).

All in all, in the apache's httpd.conf, I want to change from this:

<VirtualHost ip.address.xxx.yyy>
ServerAlias domainname.com
ServerAdmin [email protected]
DocumentRoot /home/username/public_html
BytesLog domlogs/domainname.com-bytes_log
ServerName www.domainname.com

User username
Group username
CustomLog /usr/local/apache/domlogs/domainname.com combined
ScriptAlias /cgi-bin/ /home/username/public_html/cgi-bin/
</VirtualHost>

To this:

<VirtualHost ip.address.xxx.yyy>
ServerAlias domainname.com
ServerAdmin [email protected]
DocumentRoot /home/username/public_html/html
BytesLog domlogs/domainname.com-bytes_log
ServerName www.domainname.com

User username
Group username
CustomLog /usr/local/apache/domlogs/domainname.com combined
ScriptAlias /cgi-bin/ /home/username/public_html/cgi-bin/
</VirtualHost>

(notes: I only changed DocumentRoot's path, maybe I will want to modify ScriptAlias too of course).

Will this break anything with cPanel? (since I change a path that he expects to follow his guideline)

Also, can I simply override apache's VirtualHost DocumentRoot in my user's directory with some command in ".htaccess", etc. (I suppose I can, but I don't know much about htaccess possibilities, once again i can do research, but I'm hoping it is an easy answer for someone here to answer).

Therefore if I can simply choose an override option (htaccess), my modification won't imply for me to modify the httpd.conf (which cPanel kinda manage). In my view point, if that option exists (without negative effect, e.g. major slowdown, etc.), it might be more clean to do it this way as I won't interfer with cPanel way of handling configuration, and I will have the desired effect.

I may of course wish to remap the DocumentRoot for domains and subdomains in the future (because I hate the fact that cPanel force us to put them all in the same public_html). So my question is not only to apply this to one domain.

If you have any other suggestion to do it a clean way without risking to break cPanel, feel free to provide!

Thanks for your advices.
 

dafut

Well-Known Member
Dec 14, 2005
74
0
156
Although it was with only one site on my VPS, I did something similar to handle a site that required multiple ports and hostnames.

# MOCHA's PACO Configuration
<VirtualHost paco.domain.com:8989>
ServerAdmin [email protected]
DocumentRoot /home/bilybobb/mocha/paco/htdocs
ServerName paco.domain.com
ScriptAlias /cgi-bin/mocha/ /home/bilybobb/mocha/paco/cgi-bin/
Redirect permanent index.html http://paco.domain.com:8989/cgi-bin/mocha/paco-main.pl
ErrorLog /var/log/mocha-log/paco-error_log
TransferLog /var/log/mocha-log/paco-access_log
SetEnv PERL5LIB /home/bilybobb/mocha/intranet/modules/
SetEnv MOCHA_CONF /etc/mocha.conf


User bilybobb
Group bilybobb
CustomLog /usr/local/apache/domlogs/mocha.domain.com combined


</VirtualHost>

# MOCHA's INTRANET Configuration
<VirtualHost mocha.domain.com:8998>
ServerAdmin [email protected]
DocumentRoot /home/bilybobb/mocha/intranet/htdocs
ServerName mocha.domain.com
ScriptAlias /cgi-bin/mocha/ /home/bilybobb/mocha/intranet/cgi-bin/
Redirect permanent index.html http://mocha.domain.com:8998/cgi-bin/mocha/mainpage.pl
ErrorLog /var/log/mocha-log/mocha-error_log
TransferLog /var/log/mocha-log/mocha-access_log
SetEnv PERL5LIB /home/bilybobb/mocha/intranet/modules
SetEnv MOCHA_CONF /etc/mocha.conf

User bilybobb
Group bilybobb
CustomLog /usr/local/apache/domlogs/mocha.domain.com combined
</VirtualHost>

<VirtualHost mocha.domain.com:80>
ServerAlias mocha.domain.com library.domain.com
ServerAdmin [email protected]
DocumentRoot /home/bilybobb/public_html
BytesLog /usr/local/apache/domlogs/mocha.domain.com-bytes_log
User bilybobb
Group bilybobb
ServerName mocha.domain.com

<IfModule mod_userdir.c>
Userdir disabled
Userdir enabled bilybobb
</IfModule>

<IfModule mod_php4.c>
php_admin_value open_basedir "/home/bilybobb:/usr/lib/php:/usr/local/lib/php:/tmp"
</IfModule>
<IfModule mod_php5.c>
php_admin_value open_basedir "/home/bilybobb:/usr/lib/php:/usr/local/lib/php:/tmp"
</IfModule>

User bilybobb
Group bilybobb
CustomLog /usr/local/apache/domlogs/mocha.domain.com combined
ScriptAlias /cgi-bin/ /home/bilybobb/public_html/cgi-bin/
</VirtualHost>
This is actually part of an include file that gets called in the httpd.conf file with this call:

Include "/etc/mocha-httpd.conf"

With it, the site's accessed on one of three ports (aside from the cPanel/WHM ports) and two of the ports are directed outside of the normal "public_html" structure. Of course I also had to set the Listen directive in httpd.conf to listen for the atypical ports (8989 and 8998), which I fixed to a specific IP address as well.

And it works quite well. So I don't see why what you're suggesting won't work.
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,466
31
473
Go on, have a guess
If all you want to do is to change the DocumentRoot in httpd.conf then you can go ahead - it won't affect how cPanel functions and the cPanel scripts won't change the DocumentRoot back.