What is a Document Root Folder in Cpanel Print

  • Updated on 07-May-2024
  • 29

Understanding the Document Root Folder in cPanel

When managing a website, knowing the lay of the land is crucial, especially when that "land" is your hosting environment. A key piece of terrain in this digital landscape is the document root folder, a term that pops up frequently, especially if you're navigating the world of cPanel. This guide will explore what the document root folder is, its importance, and how you can effectively interact with it.

What is the Document Root Folder?

The document root folder, often referred to as the web root, serves as the primary directory on your web server where your website's files live. It's the cornerstone of your website's accessibility on the internet. When visitors type in your website's URL, what they're accessing are the files stored within this special folder.

Info! Each domain and subdomain on your cPanel account boasts its own document root folder. Typically, for the primary domain, this is the public_html directory.

Why is the Document Root Important?

Grasping the concept and location of your document root is crucial for several reasons:

  • Website management: It's the go-to place for uploading your site's files.
  • Application installation: Whether it's WordPress or any other CMS, the document root is where you'll install them.
  • Troubleshooting: A good understanding of your document root can aid in diagnosing and fixing site issues.

How to Find Your Document Root in cPanel

Finding the document root in cPanel is straightforward:

  1. Log into your cPanel account.
  2. Head over to the Domains section and select Addon Domains or Subdomains, depending on your needs.
  3. You'll be greeted with a list of domains/subdomains and their respective document root paths.
Success! Knowing the document root path empowers you to upload, edit, or delete files using either the cPanel File Manager or an FTP client.

Best Practices for Managing Your Document Root

  • Organization: Keep your files neat by organizing them into folders within the document root.
  • Security: Exercise caution with what you upload. Remember, this folder is accessible online.
Warning! Avoid storing sensitive info like configuration files with passwords in the document root without adequate security measures.

Changing the Document Root to a Subfolder for Your Main Domain in cPanel

There might be instances where you want to point your main domain's document root to a subfolder, perhaps for a website revamp or better organization.

Warning! Altering the document root can disrupt your website's accessibility if mishandled. Always back up before making changes.

Step 1: Log into your cPanel and navigate to the File Manager under the Files section.

Step 2: If you haven't already, create a new subfolder within the public_html directory for your main domain's new document root.

Step 3: Since modifying the document root directly in cPanel might not be possible, consider using the .htaccess file for redirection as an alternative:

  • In public_html, find or create a .htaccess file.
  • Add redirection rules to point traffic to the new subfolder.
Info! This workaround doesn't change the document root but effectively redirects traffic to your designated subfolder.
 

Using .htaccess (Alternative Method)


If changing the actual document root isn't feasible, you can redirect traffic from the main public_html directory to a subfolder using the .htaccess file:

In the File Manager, navigate to the public_html directory.

Locate or create a .htaccess file.

Edit the file and add the following lines at the top:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteCond %{REQUEST_URI} !newsite/
RewriteRule (.*) /newsite/$1 [L]

Replace yourdomain.com with your actual domain name and newsite with your subfolder name.
Info! This method does not change the document root but redirects traffic to the subfolder, acting as a workaround.

Further Assistance

Should you run into any snags with finding or managing your document root, don't hesitate to open a support ticket or start a LiveChat session. Our support team is on standby to guide you through any challenges.


Was this answer helpful?

« Back