How To Change Document Root of Main Domain in cPanel
Often webmasters and cPanel server admins need to change the document root of the domain which is associated with the main cPanel account. Whilst changing the document root of an addon or sub-domain is a straightforward process, there is no official guideline from cPanel on how to change the document root of an account’s main domain.
NetShop ISP’s Support team have helped numerous customers who requested to change the document root of their main cPanel account, and so we have decided to publish in this article a 100% working solution.
Steps to Change Document Root of Main cPanel Domain
Just follow the next steps for a successful document root change of your account’s main domain name.
Step 1: Take Backup
It’s crucial that before you proceed to the next steps you take a full backup of your cPanel account.
You may do so by copying your home directory somewhere safe within the same server (assuming you have root access) as follows:
root@cpanel:~$ cp -r /home/myuserdir /root/
The above command will copy the entire “myuserdir” directory under /root/ folder.
Alternatively, you can you a reliable, off-site cloud backup software to backup your home directory, such as Acronis.
Step 2: Edit files under /var/cpanel/userdata/$USERNAME
The second step requires to edit two files under /var/cpanel/userdata/$username , where $username is the username of your account in concern. In our example the username is wwwcolocy.
There are two files to edit; the base domain and the SSL one. In our example, the domain in concern is cypruscolo.com so we will edit the two files as follows (we use “vi” as our text editor, you may use your own preferred editor):
root@localhost:~$ vi /var/cpanel/userdata/wwwcolocy/cypruscolo.com
Change the paths as indicated in the screenshot below, then save and exit the file.
Then follow the same process by editing the “documentroot” variable in the corresponding SSL file:
root@localhost:~$ vi /var/cpanel/userdata/wwwcolocy/cypruscolo.com_SSL
Step 3: Delete cache files
As you are in the same directory, there are two cache files as indicated by the screenshot below.
Delete them using the following command:
root@localhost:~$ rm -f /var/cpanel/userdata/wwwcolocy/cypruscolo.com.cache && rm -f /var/cpanel/userdata/wwwcolocy/cypruscolo.com_SSL.cache
Step 4: Update userdatacache and re-build httpd config
You are almost ready. At this point we need to execute the following commands so our changes are applied in the system.
root@localhost:~$ /scripts/updateuserdatacache
Then, execute the following command to re-build apache’s configuration:
root@localhost:~$ /scripts/rebuildhttpdconf
Step 5: Restart Apache
The final step is to restart Apache. Do so by executing the following command:
root@localhost:~$ service httpd restart
You are all set! Congratulations, you have edited the document root of your cPanel’s primary domain name!
Source: https://netshop-isp.com.cy/blog/how-to-change-document-root-of-main-domain-in-cpanel/