KrnlPanic's Linux Notes and Tips

Working with linux since kernel version 2.0.30

Updating apache default vhost in cpanel

I just spun up a new CentOS 7 Virtual Private Server (VPS), and as is always the case, needed to get the Apache server configured and operational to support the necessary Virtual Hosts (vhosts). I always have a difficult time with the Apache configuration because changes to the httpd.conf file are lost anytime the server config is rebuilt or updated through the cpanel scripts. So, it’s always tough to find the “proper” way to get changes to stick.

I like my DocumentRoot for each of my vhosts to reside within a single user’s home directory, and the default domain for the account was not aligning to that structure. Take the following example in /etc/httpd/conf/httpd.conf:

   <DocumentRoot /home/krnlpanic/public_html>

The above directive assigns the document root for to the public_html directory. That’s not where I want it, as I want my vhosts laid out as such:


So, I located this gem that will allow me to change the default DocumentRoot from /home/krnlpanic/public_html/ to /home/webadmin/public_html/

root@host [~]# cat /var/cpanel/userdata/nobody/ 
documentroot: /usr/local/apache/htdocs 
group: nobody 
hascgi: 1 
group: nobody 
ip: "*" 
phpopenbasedirprotect: 1 
port: 80 
serveralias: '' 
usecanonicalname: 'Off' 
user: nobody 
userdirprotect: ''

In file /var/cpanel/userdata/krnlpanic/ is where cpanel picks up the DocumentRoot to build out the httpd.conf file! So, make your change to the respective user domain file and then rebuild httpd.conf, as follows:

Backup your existing httpd.conf
# cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak122320

Rebuild httpd.conf (this is the cpanel way, and the same script called in the upcp cron job that wipes away any changes that you make to the file)
# /scripts/rebuildhttpdconf

Restart the httpd server
# systemctl restart httpd