Changing the web root of a cPanel acccount

cpanel_logoAs a rule I try to avoid cPanel for hosting sites, I find the overhead of the control panel and the limited flexibility too confining for all but the simplest of sites. Occasionally though I need to deploy sites at work though to cPanel servers due to client requirements.

The default web location ( ~/public_html ) for an account works well in most instances. But this default can cause issues when deploying certain applications such as Zend Framework. in which you do not want the web server serving the root of application codebase as the site root.

A common work around with cPanel environments is to create a .htaccess file in the base of the application to rewrite the path to the public root but this is a bit messy and adds another level to the application URL’s. Fortunately if you have root SSH access to the cPanel server though the path server by the webserver can be changed simply enough.

To change simply log in to the root account of the server over SSH. Then change into the userdata directory:

cd /var/cpanel/userdata/

Listing the contents of this directory will show a list of all the cPanel accounts on the machine. From here simply change into the directory with the same name as the account you would like to edit the document root for:


In this directory you will see a file named the same as the domain that belongs to the account. Edit this file and find a line that looks similar to:

documentroot: /home/USERNAME/public_html

Change the path defined in this line to the public path required by your application and save the changes. Now rebuild the apache configuration for the server with the following command:


Then restart the Apache service:

service httpd restart

Visiting the site after restarting Apache will now show you the account being served from the amended document root.

Leave a Reply

Your email address will not be published. Required fields are marked *