How-To

Changing a Document Root in cPanel

When you visit a web site, you are accessing a particular folder on a web server. For example, when you visit johns-carpentry.com, the server is pulling up the files at: /home/johnc/public_html. The web server only serves up the 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. The visitor doesn’t know the exact location where the coat is stored, but the coat does reside at a specific location.

That specific location of the web folder is the document root and is set by the Apache configuration.

But what if you wanted to change that location? 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. Changing the document root for Addon domains is easy. Simply log into your cPanel and navigate to: Domains >> Addon domains.

addon

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

addon-remove

It’s that simple!

Changing Primary domains

For changing the main/primary domain, you will need to have root SSH access and be able to locate and edit the following file (replacing your user & domain info):

/var/cpanel/userdata/USERNAME/DOMAIN.COM

1. Once you have opened the file, look for the following line:

documentroot: /home/USERNAME/public_html

2. Modify the location according to your needs. Save it and exit.

3. 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!

And, of course, if this seems a little too advanced and you’re a ServInt customer, feel free to open up a support ticket in the customer portal, and we’ll be happy to help.

Photo by Steve Gary

Find out more about ServInt solutions

Starting at $25

Comments
  1. @Derek Fong, these two methods are actually better than running the distiller because they work within the cPanel template system. When cPanel rebuilds the Apache conf, it builds it based on the template, user profiles, etc... Using these methods will always ensure that your custom directives will always be retained. It is definitely the preferred way to change your document root.
    Jacob "Boom Shadow" Tirey /
  2. Is this method a "blessed" way of customizing a DocumentRoot? cPanel provides a different method using Apache include files (which also involves using the conf distiller to record any changes made to the core httpd.conf file), but this method is by far less clunky.
  3. [...] written for the ServInt blog as part of the ‘Tech bench’ series. You can view it on the ServInt blog here. Used with permission. Related Posts:Fix: Fantastico is not installed at the default [...]
    Change a document root on cPanel | BoomShadow.net /
  • The New York Times
  • The Hill
  • Bloomberg
  • The Seattle Times
  • Computer World
  • Ars Technica
  • MSNBC