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:
<VirtualHost krnlpanic.com:80> <DocumentRoot /home/krnlpanic/public_html> ... </VirtualHost>
The above directive assigns the document root for krnlpanic.com 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/krnlpanic.com
root@host [~]# cat /var/cpanel/userdata/nobody/host.domain.com --- documentroot: /usr/local/apache/htdocs group: nobody hascgi: 1 ifmodulemodsuphpc: group: nobody ip: "*" phpopenbasedirprotect: 1 port: 80 serveradmin: email@example.com serveralias: '' servername: host.domain.com usecanonicalname: 'Off' user: nobody userdirprotect: ''
In file /var/cpanel/userdata/krnlpanic/krnlpanic.com 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)
Restart the httpd server
# systemctl restart httpd