How to Change Document Root for a cPanel Main Domain

By default, cPanel sets the main domain’s document root to public_html. However, sometimes you need to point it to a different directory — for example, a Laravel application that requires the public folder as the document root.

cPanel does not allow the change of the document root for the primary domain. Only subdomains and addon domains are allowed to change the document root.

If you have WHM or SSH root access, you can change it by editing the files

vi /var/cpanel/userdata/CPANEL_USER/DOMAIN_NAME
vi /var/cpanel/userdata/CPANEL_USER/DOMAIN_NAME_SSL

Look for the documentroot: line and change it to your desired path.

Delete the .cache versions so cPanel doesn’t reuse old values.

rm /var/cpanel/userdata/CPANEL_USER/DOMAIN_NAME.cache
rm /var/cpanel/userdata/CPANEL_USER/DOMAIN_NAME_SSL.cache

Rebuild cPanel & Apache Config

/scripts/updateuserdatacache
/scripts/rebuildhttpdconf

Restart Apache

systemctl restart httpd

Now the website will work with the new document root directory.

Back to cPanel Server

Comments

Leave a Reply

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