What is the document root?
When you visit a web site, you are accessing a particular folder on the web server. The server knows to only serve up those files located at that folder to incoming visitors. The location of that web folder is called the “Document Root”.
It is similar to using a coat check. You present your ticket to the attendant and they fetch it from the back room.
In this metaphor, the coat is the site you want to visit and the attendant is the web server. The visitor doesn’t know the exact location where the coat is stored, but the coat does reside at a specific location.
For example, when you visit johns-carpentry.com, the server is pulling up the files at:
/home/johnc/public_html. The document root is set by the Apache configuration.
What we are going to discuss today is what if you wanted to change that location? You would need to change the ‘Document root’ for the domain. cPanel’s default location may not serve your needs or you simply want to reorganize. In any case, I’ll show you how to make that change on cPanel.
Changing Addon Domains
There are two types of domains on a cPanel box that can have document roots: Main (primary) domains and Addon domains. Addon domains are easy to change the document root. Simply log into your cPanel and navigate to: Domains » Addon domains
Next, edit the Addon domain path. To do so, simply click the edit icon next to the path, and type in your new path.
It’s that simple!
Changing Primary domains
For changing the main/primary domain, you will need to have root SSH access. Edit the following (replacing your user & domain info):
Look for the following line:
Modify it according to your needs. Save it and exit.
If you are using an SSL on the domain, be sure to update the SSL’s template as well:
/var/cpanel/userdata/USERNAME/DOMAIN.COM_SSL documentroot: /home/USERNAME/public_html
Then, rebuild the Apache conf and restart Apache:
/scripts/rebuildhttpdconf service httpd restart
The change will be immediate. Simply clear your browser cache and force refresh the page!
Note about this article
This article is one I had written and shared with the ServInt blog as part of the ‘Tech bench’ series. You can view it on the ServInt blog here. They are using my article with my permission.