Change a document root on cPanel

March 30, 2012 — 2 Comments

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

Addon domains section in cPanel

Next, edit the Addon domain path. To do so, simply click the edit icon next to the path, and type in your new path.

Remove an addon domain in cPanel

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:

Then, rebuild the Apache conf and restart Apache:

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 for 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.

Jacob "Boom Shadow" Tirey

Posts Twitter

A linux web hosting administrator, a professional production sound man, and a renegade cop without nothing left to lose.... Ok, that last part is made up. In all seriousness, my passion in life is to help people; whether that be with help running their sites or with their productions. The name 'Boom Shadow' was given to me by a great group of filmmakers called Star Wipe Films. back in 2005 and has been with me since. I hope my site is helpful to you, and if there's something you need, drop me a line!
  • Alexander P

    thank you

  • Brilliant thanks, guess I will have to set my own cpanel standard to auto put the main public html dir into a domain folder instead of /public_html. Just went through all my domains and updated then moved files into the new folders.