How to change the Primary Domain Root in cPanel/WHM

We’ll show you how to alter the principal domain document root in this article’s cPanel/WHM panel.

  1. As the root user, log in to your server using SSH. If you want to connect to your Linux server through SSH from a Windows PC, you can use Putty or Bitvise SSH client software.
  2. Navigate to the given path using your favorite text editor and edit the domain name file. If something goes wrong, it’s a good idea to make a backup of the file before making changes. As an example, we’ve utilized a nano text editor.
# nano/var/cpanel/userdata/username/domainname.com

Note: Replace username with the username of your cPanel account and domainname.com with the name of your main domain.

You must look in the domain name file for the following two lines.

documentroot: /home/username/public_html
path: /home/username/public_html/CGI-bin

Once you’ve located those two lines in the domain name file, you’ll need to alter them to point your main domain’s document root to a subdirectory within the public_html directory. We’ve added the nick test as a subfolder in the document root and path.

documentroot: /home/username/public_html/nicktest
path: /home/username/public_html/nicktest/cgi-bin

After you’ve finished editing the lines, you’ll need to save the files. If you’re using a nano text editor to open the file, you’ll need to hit Ctrl + X to save it. After that, in the Save changed buffer? (Answering “No” will DISCARD changes.) option, type Y or Yes.

Then you must erase your principal domain’s cache file. To do so, type the following command into your terminal:

# rm -vf /var/cpanel/userdata/username/domain.com.cache

Note: Replace username with the username of your cPanel account, and domainname.com with the name of your principal domain.

If you have an SSL Certificate placed on your main domain, you must change the following file like you did in step 3.

# volcano /var/cpanel/userdata/username/domain.com_SSL

Note: Replace username with the username of your cPanel account, and domainname.com with the name of your principal domain.

Now, you must look in the domain name file for the following command:

documentroot: /home/username/public_html

Once you’ve located those two lines in the domain name file, you’ll need to alter them to point your main domain’s document root to a subdirectory within the public_html directory. We’ve added the nick test as a subfolder in the document root and path.

documentroot: /home/username/public_html/nicktest

After you’ve finished editing the lines, you’ll need to save the files. If you’re using a nano text editor to open the file, you’ll need to hit Ctrl + X to save it. After that, in the Save changed buffer? (Answering “No” will DISCARD changes.) option, type Y or Yes.

Then you must erase your principal domain’s cache file. To do so, type the following command into your terminal.

$ rm -vf /var/cpanel/userdata/username/domain.com_SSL.cache

Note: Replace username with the username of your cPanel account and domainname.com with the name of your main domain.

You must run the following instructions in the terminal after deleting the cache file of your primary domain. These commands update the cPanel cache files and the cPanel settings, then back up and restart the Apache service on the server that cPanel uses.

# /scripts/updateuserdatacache
# /scripts/updateuserdomains
# cp /etc/apache2/conf/httpd.conf{,.bak-`date +%Y%m%d`}
# /scripts/rebuildhttpdconf
# /scripts/restartsrv_httpd

After completing all of the procedures above, the domain will load content from the new document root you provided. That is all there is to it.