Change the document root in cPanel

For this you will need root SSH access to you cPanel to change the root of the main domain.

1. Connect to your server via SSH as root user.

2. User your favourite editor ( I use nano ) and edit the following file placing USERNAME and DOMAIN.COM with your username and domain:

 nano /var/cpanel/userdata/USERNAME/DOMAIN.COM

You need to edit 2 lines in this document replacing USERNAME and NEW_SUB_DIRECTORY with your own sub directory name:

documentroot: /home/USERNAME/public_html/NEW_SUB_DIRECTORY

path: /home/USERNAME/public_html/NEW_SUB_DIRECTORY/cgi-bin

Save the file and then delete the cache of that file by running this command:

rm -vf /var/cpanel/userdata/USERNAME/DOMAIN.COM.cache

3. If your domain has a SSL certificate installed edit the following the same way as above:

nano /var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL

Save the file and then delete the cache for the domain SSL:

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:


5. Then restart Apache server to apply changes:

service httpd restart