1/20/2015 – Change a Document Root in cPanel
Posted by Jamison on 20 01 2015.
Every web page or website that you visit has a particular storage. Every time you go to a website, you are actually accessing through series of folders where that page you are visiting is located. This location is called document root. This holds true when you are looking for a file on your computer that is stored at a specific folder. You keep on looking for the file, folder after folder until you reach the origin of its location.
If you are using cPanel on your website, sometimes you want to change the document root settings—you may want to reorganize and de-clutter your website. This article will show you how to do this.
Two types of domains that you can change document root are Addon and Main domain. Let’s discuss Addon domains first. Here’s how.
Changing Document Root for a Subdomain or an Addon
To change the document root on addon is much simpler than changing for the main domain. And it’s done in just three simple steps.
- Open you cPanel account and look for Domains, then click on Addon Domains. This will open the Modify Addon Domain page.
- Edit the domain path by clicking the edit icon under the Document Root column. Look for the document root you wish to change. Beside this path or link is the edit icon. Click it and a pop-up window will appear.
- Enter the document root you wish to put your files or webpages on and then click Change.
And that’s it! Simple and literally effortless.
Changing Document Root for the Main Domain
Now for the primary domain, there are two ways to do this—1) by changing the domain name as the root user; and 2) by getting root access and rewriting the URL. Let’s discuss the first one.
- You need to be more careful when changing the domain name as this could damage your file. You might even need to contact your hosting provider before doing this. To start, login to your account and look for View Hosting Packages. Select the one that you want to change and then click Change My Domain. Register a new name and you are done.
Please note that the new name should not be identical with any of your domains.
- The second process will need you to have root SSH access so you can edit or rewrite the URL. No you don’t necessary need ample knowledge of coding. Just follow this simple trick below. And oh! Please make sure that your SSH’s template is updated.
- Login to your cPanel account.
- To gain shell access, you can simply use SSH. Right now you should be looking a URL such as this: /var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL
- Enter your cPanel’s account name replacing Username and then enter your main domain name replacing domainname.com
- Now, look for Text Documentroot and then start making your necessary changes. The document root should be looking like this: /home/USERNAME/public_html
- Now change the URL with /home/USERNAME/public_html/NEW_PATHà change username and new_path accordingly.
- After it’s done, you need to rebuild Apache and restart its server. Follow this for the exact command:
# service httpd restart
- Changes will be made immediately and be permanently updated.
Yup! The latter process may seem a little complex, but actually it’s not. Just carefully follow these directions and you’ll be fine. Good luck!