The Document Root Folder plays a critical role in determining how your website is served to visitors. Anyone managing a website needs to understand its purpose and how to work with it effectively.
The Document Root Folder is the primary directory on a web server where the files for a specific website are stored. It acts as the entry point for your website, serving as the location from which the web server retrieves and delivers files to users when they visit your domain.
For example, if your website is accessible at www.example.com, the server uses the document root folder to locate the files (HTML, CSS, images, scripts) that should be displayed in the browser.
Default Document Root Locations
The document root folder’s location depends on the web hosting platform and server configuration:
- For Shared Hosting:
- The document root is typically located at:
/public_html/
This directory stores all files accessible via your domain.
- For Subdomains:
- Subdomains (e.g., example.com) usually have their document root folder, such as:
/public_html/blog/.
- Subdomains (e.g., example.com) usually have their document root folder, such as:
- For Addon Domains:
- Additional domains hosted under the same account also have separate document root folders:
/public_html/addondomain/.
- For Local Servers:
- On a local development environment, the document root might be located in a directory like:
/var/www/html/ (common for Apache servers).
How to Locate Your Document Root Folder
Depending on your hosting control panel, you can find the document root folder by:
- Using cPanel:
- Log in to cPanel.
- Navigate to Domains → File Manager.
- Select the domain or subdomain to view its associated document root.
- Using Plesk:
- Log in to Plesk.
- Open the domain management section.
- The document root folder is displayed under the domain settings.
- Via SSH or FTP:
Access your server through SSH or FTP and navigate to the directory associated with your website.
Customizing the Document Root Folder
Web servers allow customization of the document root folder for advanced setups or personal preferences.
- On Apache: Modify the DocumentRoot directive in the server’s configuration file (httpd.conf or apache2.conf). Example:
- DocumentRoot "/path/to/custom/root"
- Ensure you restart the Apache service after making changes.
- On Nginx: Edit the server block in your configuration file and specify the root directive:
- root /path/to/custom/root;
- Reload Nginx for the changes to take effect.
Common Issues and Troubleshooting
- 403 Forbidden Error: This occurs when the document root folder lacks proper permissions or an index file. Ensure the folder and files have the correct read permissions.
- 404 Not Found Error: Check if the requested files are placed in the correct document root directory and that the server points to the correct location.
- Misconfigured Subdomains: Verify that subdomains are pointing to their respective document root folders in your hosting settings.