Change Primary Domain Document Root in cPanel/WHM

_.:=iTake=:._

Administrator
Staff member
Credits
1,519
#1
The cPanel accounts are created using a primary domain. All primary domains on the hosting account use “public_html” directory for all its website files and data. The sub-directories inside the public_html directory is occupied by the addon domains. The primary domain can also be setup to use a sub-directory inside public_html directory instead of public_html itself. Follow the below steps to change the document root of your primary domain in cPanel account. Please note that, you will need to have root SSH access to perform these steps.

1) Connect to your server via SSH as root user. You may follow the tutorial below, if you are using a Windows system to connect to your server via SSH. This tutorial explains how to use “Putty”, SSH client software to access server.

2) Using your favorite text editor (say vim) edit the following file.

$ vim /cpanel/userdata/username/domain.com
Replace the “username” with your cPanel account username and “domain.com” with your primary domain name and “subdir” with your new directory. Find the following two lines in this file.

documentroot: /home/username/public_html
path: /home/username/public_html/cgi-bin
Modify these two lines to change the document root of your primary domain to a sub-directory inside “public_html” directory.

documentroot: /home/username/public_html/subdir
path: /home/username/public_html/subdir/cgi-bin
Save the file after changes are made and then delete the cache file for your primary domain.

$ rm -vf /var/cpanel/userdata/username/domain.com.cache
3) If the primary domain has an SSL certificate installed, edit the following file the same way as above.

$ vim /var/cpanel/userdata/username/domain.com_SSL
Save the file after changes are made and then delete the cache file for your primary domain.

$ rm -vf /var/cpanel/userdata/username/domain.com_SSL.cache
4) Run the following scripts to update the user data cache and rebuild apache configuration file.

/scripts/updateuserdatacache
/scripts/rebuildhttpdconf
5) Restart Apache server to load changes.

$ service httpd restart

Source: https://www.interserver.net/tips/kb/change-primary-domain-document-root-cpanelwhm/
 

_.:=iTake=:._

Administrator
Staff member
Credits
1,519
#2
this is very useful if Cpanel is messing up and u can't fix issues like this. It's important to rebuild userdata else changes won't take effect..
 
Last edited:
Top