How to Modify the Document Root for a Subdomain in cPanel Make it Rain Paper

  • DNS, DNS Management, DNS Configuration, Subdomains
  • 0

Each subdomain in your cPanel account has its own document root, which is the directory where the files for that subdomain are stored. In certain cases, you may need to change the default document root for your subdomain. In this guide, we will show you how to safely modify the document root for a subdomain, along with restrictions on which directories can be set as the document root.

What Is a Document Root?

The document root is the folder on your server that contains all the files for a specific domain or subdomain. When users visit your subdomain (e.g., subdomain.yourdomain.com), the server serves content from the directory set as the document root. By default, cPanel assigns a document root for each subdomain, but you can change this to another directory if needed.

When Should You Modify the Document Root?

You might want to modify the document root if:

  • You want to reorganize your file structure for better management.
  • You need to point your subdomain to a different directory where a different website or application is hosted.
  • You are migrating content from one directory to another.

Step-by-Step Guide to Modify the Document Root for a Subdomain

To modify the document root for a subdomain in your cPanel account, follow these steps:

Step 1: Access the Subdomain Management Section

  1. Log in to your cPanel account.
  2. In the Domains section, click on the Subdomains icon.
  3. Scroll down to the list of existing subdomains that are associated with your account.

Step 2: Select the Subdomain to Modify

  1. Find the subdomain whose document root you want to change.
  2. Click the notepad icon (often labeled as Edit or Manage) next to the subdomain.

Step 3: Enter the New Document Root

  1. In the text box labeled Document Root, enter the new file path that you want to use as the document root for the subdomain.
  2. Ensure the new directory is within your account's home directory (i.e., /home/yourusername/), as cPanel restricts certain directories from being used as the document root.

Directory Restrictions for Document Roots

When changing the document root for a subdomain, certain directories cannot be used. These restrictions are in place for security and functionality reasons. The following directories are not allowed as a document root:

  • Your account's home directory itself (/)
  • Directories outside of your home directory (e.g., ./ and ../)
  • .cpanel
  • .trash
  • etc
  • mail
  • ssl
  • tmp
  • logs
  • .cphorde
  • .spamassassin
  • .htpasswds
  • var
  • cgi-bin
  • .ssh
  • perl5

Be sure to choose a directory that does not conflict with these restricted directories.

Step 4: Save Your Changes

  1. After entering the new document root, click Change to save your modifications.
  2. Your subdomain will now point to the new directory you have specified. The changes should take effect immediately, although DNS propagation might take a few minutes in some cases.

Verifying the Changes

Once you have modified the document root, visit the subdomain to ensure the website or application is loading correctly from the new directory. You may need to upload new files or adjust file permissions if they differ between directories.

Additional Notes

  • If you encounter any errors after changing the document root, double-check that the new directory path is correct and that all necessary files are present in the directory.
  • Always back up your website and configurations before making major changes like modifying the document root, to avoid data loss in case of misconfiguration.

Modifying the document root for a subdomain can help you better manage your server's file structure or change the content that a subdomain points to. With the clear steps outlined above, you can confidently adjust your document root without causing disruptions to your website. Remember to avoid using restricted directories and always verify your changes once the modification is complete.


Did this answer help?

« Back