How to change document root of main domain in cpanel can seem daunting, but it’s a straightforward process if you follow the correct steps. Whether you’re reorganizing your website’s structure, migrating to a new content management system (CMS), or simply prefer a different directory, this guide will walk you through every step to ensure a smooth transition.
What is the Document Root?
Before diving into the process, let’s clarify what the document root is. The document root is the directory on your web server where your website’s files are stored. When someone visits your website, the server retrieves files from this directory to display your content. For example, if your website is www.example.com, the document root could be /public_html or another directory you designate.
Why Change the Document Root?
There are several reasons you might want to change the document root for your main domain:
- Reorganization: You might want to move your website’s files to a different directory for better organization.
- Security: Changing the document root can add an extra layer of security, making it harder for attackers to locate your files.
- CMS Migration: If you’re switching from one CMS to another, the new CMS might require a different directory structure.
- Multi-Site Hosting: If you manage multiple websites from a single cPanel account, you might want each site to have its document root.
Prerequisites
Before you begin, ensure that you have:
- cPanel Access: You’ll need to log in to your cPanel account.
- Backup: Always back up your website files and databases before making changes to the document root.
- Knowledge of File Structure: Familiarity with your website’s file structure will help you avoid mistakes during the process.
Step-by-Step Guide to Changing the Document Root in cPanel
Step-1: Log in to cPanel
- Open your web browser & navigate to your C-Panel login page. This is usually found at https://yourdomain.com/cpanel or https://yourdomain.com:2083.
- Enter your cPanel username and password, then click “Log in.”
Step-2: Access the File Manager
- Once logged in, scroll down to the “Files” section.
- Click on “File Manager.” This will open a new tab or window displaying your website’s files and directories.
Step-3: Create the New Document Root Directory
- In the File Manager, navigate to the root directory, usually /public_html.
- To create a new document root, click on the “+ Folder” button at the top left.
- Name your new folder (e.g., new_root), and ensure it is located within the /public_html directory or another location of your choosing.
- Click “Create New Folder.”
Step-4: Move Website Files to the New Directory
- After creating the new directory, move your website’s files to this new location.
- Select all files and folders within your current document root (e.g., /public_html) by holding down the Ctrl key (Windows) or Command key (Mac) while clicking on each item.
- Right-click on the selected files, choose “Move,” and then specify the new directory (e.g., /public_html/new_root).
- Click “Move Files” to complete the transfer.
Step-5: Modify the Document Root in cPanel
- Return to the main cPanel dashboard.
- Scroll down to the “Domains” section and click on “Domains” or “Addon Domains” depending on your setup.
- Find your main domain in the list and click “Manage.”
- Looking for an option labeled “Document Root” or “Root Directory.”
- Enter the path to your new document root (e.g., /public_html/new_root).
- Click “Save Changes” or “Update” to apply the new document root.
Step-6: Test Your Website
- After making the changes, it’s essential to test your website to ensure everything is working correctly.
- Open a new browser tab and enter your website’s URL.
- Navigate to different pages to verify that all content is loading correctly. If you encounter any errors, check that all files were moved properly and that no paths are broken.
Step-7: Update Any Hard-Coded Paths
- If your website uses hard-coded paths, you’ll need to update them to reflect the new document root.
- Search your website’s files for references to the old document root and replace them with the new path.
Common Issues and Troubleshooting
- Internal Server Error (500): This often occurs due to incorrect file permissions or missing .htaccess files. Ensure all files have the correct permissions, and your .htaccess file is present in the new document root.
- Broken Links or Missing Images: If you notice broken links or missing images, double-check that all files were moved to the new document root and that any hard-coded paths are updated.
- CMS-Specific Issues: Some content management systems, like WordPress, have settings that define the document root. You might need to update these settings within your CMS to match the new directory.
Conclusion
How to change document root of main domain in cpanel, Changing the document root of your main domain in cPanel is a task that can be accomplished with a few steps, provided you approach it with care. Remember to back up your files before making changes, move your files carefully, and test your website thoroughly afterward. Whether you’re doing this for reorganization, security, or CMS migration, these steps will help you achieve a smooth transition.
By following this guide, you can confidently change the document root in cPanel and ensure your website continues to function seamlessly.
