cPanel/WHM is a popular and most advanced web hosting control panel to manage Linux operating system based hosting . By default cPanel document root is /home/username/public_html. Where username is your cPanel username. Sometimes depending on your project requirement, you need different  document root directory.

You can consider two environments to change primary domains document root directory.

1.On Shared Hosting Environment

If you have shared hosting. On shared hosting its a bit tricky to change document root of main domain as you will not have admin rights. What you can do is create a symbolic link pointing to the desired directory and name this symbolic link as public_html.

 2. On VPS and Dedicated Servers

Its easy to change primary domains root in cPanel on VPS or Dedicated server. You need root access to perform this task. Server can be accessed with you root login and password. To access server you need one of the SSH client software, mine is PUTTY.

Install PUTTY, click here to download if you have not PUTTY installed previously.

How to login with PUTTY?

1. Open PUTTY

2. Type your server ip or host  name and press enter.You will be prompted with PUTTY  CLI .

3. Enter root username, type your password.  Password you type will be invisible, type correct password and press enter.

Now you are logged in to your server with root access.

Now edit the following file:

# vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM
For SSl: # vim /var/cpanel/userdata/USERNAME/DOMAINNAME.COM_SSL
where USERNAME is the cpanel username of related user and DOMAINNAME.COM is the primary domain name.

Once file is opened, type i to inter editing mode. Locate following line:
documentroot: /home/USERNAME/public_html/NEW_PATH

Change path as per your requirements.
To Escape from VIM Text editor:
  1. you need to switch to command mode. This can be done by hitting the Esckey. Next, you can type the following commands:
  2. :q to quit.
  3. :q! to quit without saving data/file.
  4. : x save and quit.
  5. :qa to quit all open files.
  6. Please note that whenever you type :, a vim or vi : will appear at the bottom of the screen. You need to type the rest of the command at the bottom of the screen.

Now after editing the file, you need to rebuild  configuration file and restart the apache server using following command:

/scripts/rebuildhttpdconf 
service httpd restart

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

Leave a comment

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