How to change the primary domain document root in cPanel/WHM panel? Print

  • 0

In this article, we will guide you on how to change the primary domain document root in cPanel/WHM panel.

  1. Login into your server through SSH as root user. If you are using a Windows system to connect to your Linux server via SSH, you can use Putty or Bitwise SSH client software to access the server.

  2. Go to the mentioned path and edit the domain name file with your favorite text editor. It's a good idea to make a backup of the file before making edits if something goes wrong. Here, we have used a nano text editor as an example.

    # nano /var/cpanel/userdata/username/domainname.com

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

  3. Now, you need to locate the following two lines in the domain name file.

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


  4. Once you find those two lines in the domain name file, you need to modify them to change the document root of your primary domain to a sub-directory inside the public_html directory. Here, we have entered nicktest as a subdirectory in the document root and path.

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


  5. Once you edit the lines, you need to save the files. If you are using a nano text editor to open the file, to save the file, you need to press Ctrl + X. After then, you need to enter Y or Yes in the Save modified buffer? (Answering "No" will DISCARD changes.) option.

  6. Then you need to delete the cache file of your primary domain. For that, you need to fire the following command in the terminal.

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

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



  7. If you have installed an SSL Certificate on the primary domain, you need to edit the following file in the same way you did in the step 3.

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

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

  8. Now, you need to locate the following two lines in the domain name file.

    documentroot: /home/username/public_html

  9. Once you find those two lines in the domain name file, you need to modify them to change the document root of your primary domain to a sub-directory inside the public_html directory. Here, we have entered nicktest as a subdirectory in the document root and path.

    documentroot: /home/username/public_html/nicktest

  10. Once you edit the lines, you need to save the files. If you are using a nano text editor to open the file, to save the file, you need to press Ctrl + X. After then, you need to enter Y or Yes in the Save modified buffer? (Answering "No" will DISCARD changes.) option.

  11. Then, you need to delete the cache file of your primary domain. For that, you need to fire the following command in the terminal.

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

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

  12. After deleting the cache file of your primary domain, you need to run the following commands in the terminal. These commands update the cache files on the system that cPanel uses, the cPanel configuration, and back up and restart the Apache service.

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


  13. After performing all the above steps the domain will load content from the new document root which you have specified. That's all.



Was this answer helpful?

« Back

chat