How to change the document root for an Addon Domain or Subdomain

Changing the document root for an addon domain or subdomain is a common task when managing multiple websites on a shared hosting account or a server. The document root refers to the folder on the server where the files for a particular domain or subdomain are stored. By changing the document root, you can customize the location where files for that domain are served, which is particularly useful when you want to organize your directories or move a site to a different folder.

This guide will explain how to change the document root for both addon domains and subdomains in different environments, including cPanel, Plesk, and manual configuration on Apache or NGINX servers.

What is a Document Root?

The document root is the directory where the web server looks for the files to serve for a particular domain or subdomain. For instance, for the main domain, the document root is typically the public_html folder, while for addon domains or subdomains, it could be a subdirectory inside public_html, like public_html/addondomain.com.

Changing the document root essentially changes the directory from which your domain or subdomain is served. This can be helpful in the following cases:

  • When moving a site to a different directory for organizational purposes.

  • When switching to a new content management system (CMS).

  • If you want a subdomain to serve content from a different directory than initially set up.

1. Changing Document Root for Addon Domain or Subdomain in cPanel:

cPanel is a widely used control panel in hosting environments, and it offers a straightforward method for changing the document root of addon domains and subdomains.

Steps to Change the Document Root in cPanel for an Addon Domain:

  1. Login to cPanel:

Open your browser and go to https://yourdomain.com/cpanel.

Enter your cPanel username and password to log in.

  1. Navigate to the “Domains” Section:

In the cPanel dashboard, scroll down to the Domains section.

Click on Addon Domains.

  1. Find Your Addon Domain:

You will see a list of your addon domains. Find the addon domain for which you want to change the document root.

Click the Edit icon (usually a pencil icon) next to the addon domain you want to modify or click on manage in some cases.

  1. Change the Document Root:

In the document root field, enter the new path for the directory you want to use for this addon domain. You can specify an absolute path, such as /home/yourusername/new-folder/, or a relative path, such as public_html/addonnew.

Make sure the new directory exists or create it beforehand.

  1. Save Changes:

Click Save or Update to save your changes.

Your addon domain will now serve files from the new document root you specified.

Steps to Change the Document Root for a Subdomain in cPanel:

  1. Login to cPanel:

Login to your hosting account using the same method mentioned above.

  1. Go to the “Subdomains” Section:

Scroll down to the Domains section and click on Subdomains.

  1. Locate the Subdomain:

You will see a list of all your subdomains.

Find the subdomain for which you want to change the document root.

4. Modify the Document Root:

In the Document Root field next to the subdomain, type in the path to the directory where you want to serve the subdomain’s files.

This could be a folder in the public_html directory or another directory of your choice.

5. Save Changes:

Once you have entered the new document root path, click Save.

The subdomain will now pull files from the new folder.

2. Changing the Document Root in Plesk:

Plesk is another popular web hosting control panel similar to cPanel. You can change the document root for addon domains and subdomains in a few easy steps:

Steps to Change the Document Root in Plesk:

  1. Log in to Plesk:

Navigate to your Plesk login page (usually https://yourdomain.com:8443) and enter your username and password.

  1. Go to “Websites & Domains”:

On the dashboard, go to the Websites & Domains tab.

  1. Select the Domain or Subdomain:

You will see a list of domains and subdomains you have added to Plesk.

Click on Hosting Settings for the domain or subdomain you want to modify.

4. Modify the Document Root:

Under Document Root, you will see the current path where files are being served from.

Enter the new directory path in the Document Root field.

 

5. Apply the Changes:

Click OK or Apply to save the changes.

Your domain or subdomain will now serve content from the new document root.

3. Changing the Document Root on Apache:

If you are managing your own server using Apache and want to change the document root for a domain or subdomain manually, you’ll need to edit the virtual host configuration files.

Steps to Change the Document Root in Apache:

  1. Access the Apache Configuration File:

Open a terminal and access your Apache configuration file. Typically, virtual host configuration files are stored in /etc/httpd/conf/httpd.conf (CentOS) or /etc/apache2/sites-available/ (Ubuntu/Debian).

You may need to use sudo privileges to edit these files.

  1. Locate the VirtualHost Block for the Domain/Subdomain:

Look for the <VirtualHost> block that corresponds to the domain or subdomain you want to modify.

3. Change the Document Root:

Change the DocumentRoot directive to the new path where you want to serve your website from:

4. Save and Restart Apache:

Save the changes and close the editor.

Restart Apache for the changes to take effect:

4. Changing the Document Root on NGINX:

NGINX uses a similar configuration file structure to Apache but uses server blocks instead of VirtualHost blocks.

Steps to Change the Document Root in NGINX:

  1. Access the NGINX Configuration File:

Open the terminal and access the NGINX configuration file, typically stored in /etc/nginx/sites-available/ on Ubuntu/Debian or /etc/nginx/conf.d/ on CentOS.

Use a text editor like nano or vi to open the file.

  1. Locate the Server Block for the Domain/Subdomain:

Inside the configuration file, find the server block corresponding to the domain or subdomain you want to modify:

3. Change the Root Directive:

Update the root directive to point to the new directory:

4. Save and Restart NGINX:

Save the changes and close the editor.

Restart NGINX to apply the changes:

Changing the document root for an addon domain or subdomain is a simple yet powerful way to manage multiple websites on a server. Whether you are using cPanel, Plesk, Apache, or NGINX, the process involves identifying the current directory where files are served from and modifying it to point to a new location. Be sure to test your website after making changes to ensure everything is working properly from the new document root.

By properly organizing your document roots, you can better manage your websites and keep your file system clean and efficient.