How to change document root via SSH (Cpanel, Linux, CloudLinux)

  1. Login to your cPanel account.

  2. To gain shell access, you can simply use SSH. Right now you should be looking a URL such as this


Replace any instances of "USERNAME" with your correct linux / cpanel username

documentroot: /home/username/publichtml path: /home/username/publichtml/cgi-bin

Find the correct Text Document root and edit these two lines to change the document root of your primary domain to now be a sub-directory inside “public_html” directory.

The document root syntax should follow similar below:

documentroot: /home/username/publichtml/subdir path: /home/username/publichtml/subdir/cgi-bin

Save the file changes and then delete the cache file of your primary domain (Seen below)

$ rm -vf /var/cpanel/userdata/username/

If your domain name has an SSL certificate installed, you will need to modify the following file in the same way as the previous step. Its important not to forget to delete your cache as the changes wont be visible otherwise.

$ vim /var/cpanel/userdata/username/domain.com_SSL

After the changes have been made, make sure to save the file correctly, not changing the file name.

Once the changes have been made, remember to delete your domains cache by using the following line of code:

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

After this is completed, rebuild Apache and restart the server. Make sure that the file is modified correctly prior to restarting as if there is any part of the syntax is missing the domain may not load correctly.

# /scripts/updateuserdatacache# /scripts/rebuildhttpdconf# service httpd restart