Skip to content

How to Change Document Root of Primary Domain in WHM/cPanel

cPanel is the most popular web-based control panel available for Redhat based systems. Use this tutorial to find how to Change Document Root of Primary Domain in cPanel server using shell access.

Steps
3
Category
Web Servers
Covers
cPanel
On this page 3 steps

cPanel/WHM is a web-based control panel to manage complete Linux operating system. All the cPanel accounts are created using one primary domain. This article will help you to change documentroot for the primary domain of cPanel user.

You must have root shell access for changing the main/primary domain document root in cPanel, Use following steps to change document root of your primary domain in cPanel account.

Prerequisites

You must have SSH access to root user to cPanel server.

Step 1 of 3Update Document Root in cPanel

Use SSH to get shell access for your server as root account, using your favorite ssh client. I have connected our server using PuTTY. Now edit following file.

vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM

Change USERNAME with your cPanel account name.
Change DOMAINNAME.COM with your Primary domain name.

After editing file, search for text documentroot and change path as per your requirements.

documentroot: /home/USERNAME/public_html/NEW_PATH

Step 2 of 3Changes Document Root for SSL

If your site is configured to run with ssl, then you also need to edit following file along with the step 1.

Edit file in text editor

vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL

and apply the same changes as above.

documentroot: /home/USERNAME/public_html/NEW_PATH

Step 3 of 3Rebuild and Restart Apache

After making changed, we need to rebuild Apache configuration file and restart Apache server. Use following command to do it.

/scripts/rebuildhttpdconf
service httpd restart

Your changes will be permanently updated. Check your site for reflecting changes.

Read this: Install and Secure cPanel from DDOS Attack with CSF

Thanks You! for using this article.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

3 Comments

  1. It points the domain but gives the error “No input file specified.” so no PHP or HTML file run on new path. There must be something else to be edited.

  2. It should be noted that if the site uses SSL an addtional/alternate file needs to be edited:

    /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top