Need Assistance?

In only two hours, with an average response time of 15 minutes, our expert will have your problem sorted out.

Server Trouble?

For a single, all-inclusive fee, we guarantee the continuous reliability, safety, and blazing speed of your servers.

How to Change the Document Root of a Domain in a cPanel Server

Table of Contents

When managing a website on a cPanel server, you may sometimes need to change the document root — the directory where your domain loads its files. This is common when restructuring a project, migrating applications, or setting up a custom framework such as Laravel, React, or Angular. In this guide, we’ll walk through all the practical ways to change document root in cPanel server, including the WHM method and the technical Method 2: Editing /var/cpanel/userdata/ files on the server.

Why Change the Document Root in cPanel?

You may need this when:

  • Deploying applications with a public folder (Laravel, frameworks).
  • Hosting multiple applications under the same account.
  • Moving a website to a new location.
  • Security hardening (moving core files outside public_html).
  • Testing staging sites.

If you have WHM access (root/ reseller), this is the easiest method.

Steps

1. Log in to WHM

Access WHM using:

https://your-server-ip:2087

2. Search for “Manage User Domains”

Go to:

WHM → Account Functions → Manage User Domains

3. Locate the Domain

Find the domain you want to modify.

4. Update the Document Root

Replace the existing document root (e.g., /home/user/public_html) with your desired directory, such as:

/home/user/newsite/public

5. Save Changes

Click Save.

6. Rebuild Apache Config & Restart Services

If not done automatically, run the following commands via SSH:

/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd

Your new document root is now active.

METHOD 2: Change Document Root by Editing /var/cpanel/userdata/ Files (Advanced Method)

This method is useful when:

  • WHM doesn’t allow the change.
  • You have customized configurations.
  • The system is showing mapping conflicts.
  • You want full control and root-level tuning.

Steps

1. SSH into the Server

Login as root:

ssh root@your-server-ip

2. Locate Userdata Files

Each cPanel account has config files located at:

/var/cpanel/userdata/USERNAME/

Inside, you will find files like:

  • domain.com
  • domain.com_SSL
  • main
  • main_SSL

3. Edit the Domain File

Open the domain file:

vim /var/cpanel/userdata/USERNAME/domain.com

Look for:

documentroot: /home/USERNAME/public_html

Change it to your new directory:

documentroot: /home/USERNAME/newproject/public

4. Edit the SSL Version Too

Update:

documentroot: /home/USERNAME/newproject/public

5. Rebuild the Apache Configuration

Run:

/scripts/rebuildhttpdconf

6. Restart Apache

/scripts/restartsrv_httpd
/usr/local/cpanel/bin/userdata_update

After this, your domain will start loading from the new document root.
 Important Notes

  • Ensure the new document root directory has correct permissions (usually 755).
  • Clear browser and CDN cache if changes do not reflect.
  • Always take a backup of the old userdata files before editing.

Conclusion

Changing the document root in a cPanel server is simple when using WHM, but even without WHM, advanced users can modify the configuration manually through /var/cpanel/userdata/. Both methods are safe and effective when done correctly.

Whether you’re deploying a new application, reorganizing files, or improving security, updating the document root ensures your site loads exactly from the location you want.

Changing the document root in cPanel can be a simple task, but incorrect configurations may lead to website downtime or errors. If you prefer expert assistance or want to avoid potential risks, our experienced team is here to help. With our reliable cPanel Server Management Services, we ensure secure server configurations, seamless domain management, and uninterrupted website performance.

Liked!! Share the post.

Get Support right now!

Start server management with our 24x7 monitoring and active support team

Subscribe and get your first issue fixed for Free!

Looking for server support and 24x7 monitoring?

Have doubts? Connect with us now.