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 your 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:
- Edit the above command, replacing the “username” with your cPanel account username and “domain.com” with your primary domain name and “subdir” with your new directory. Find the following two lines in this file:
- Now, look for Text Documentroot and edit these two lines to change the document root of your primary domain to now be a sub-directory inside “public_html” directory. The document root should look like this:
- Save the file after changes are made and then delete the cache file for your primary domain:
$ rm -vf /var/cpanel/userdata/username/domain.com.cache
- If the primary domain has an SSL certificate installed you will need to modify the following file in the same way as above:
$ vim /var/cpanel/userdata/username/domain.com_SSL
- After your changes are complete save the file and then delete the cache for your primary domain:
$ rm -vf /var/cpanel/userdata/username/domain.com_SSL.cache
- 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!