How to change the root directory for the main domain in cPanel

The default root directory for the main domain of your account in cPanel is

/home/USERNAME/public_html/

and there is no way to change it from the cPanel GUI. You can change it only if you have root access to the server.

Steps to change the root directory for the main domain:

1. Connect to your server with SSH as root

2. Navigate to /var/cpanel/userdata/[USERNAME]/

cd /var/cpanel/userdata/[USERNAME]/

3. Here, edit the files

/var/cpanel/userdata/[USERNAME]/[DOMAIN_NAME]
/var/cpanel/userdata/[USERNAME]/[DOMAIN_NAME]_SSL

For example, for account “plothost” with domain plothost.com, the filenames would be:

/var/cpanel/userdata/plothost/plothost.com
/var/cpanel/userdata/plothost/plothost.com_SSL

4. In the above two files, look for the line:

documentroot: /home/[USERNAME]/public_html

and replace “public_html” with the desired new root location.

5. Rebuild the Apace configuration

# /scripts/rebuildhttpdconf
root@web [~]# /scripts/rebuildhttpdconf
Built /etc/apache2/conf/httpd.conf OK

6. Restart Apache web server

# service httpd restart
root@web [~]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
root@web [~]#

Now, access the site. It should be loaded from the new location.

cpanel logo
cPanel Logo

Leave a Reply