I want to change root directory of "public_html" to public

Posted March 1, 2021 568 views

I went to WHM Terminal and trying to change root of “public_html” by this code “/var/cpanel/userdata/username/” it showing permission denied, So how I can solve this issue ?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

As you may know, directly modifying the Apache config on a cPanel server is not a good idea as your changes would be lost after the next Apache rebuild.

Also changing the document root for an Addon domain name on a cPanel server is pretty straightforward. However, occasionally you would like to do this for your main domain name as well.

Here’s one of the easy ways on how to do that:

You would need root shell access and then follow these simple steps:

Open the following file:

nano /var/cpanel/userdata/your-cpanel-user/

Modify the documentroot accordingly:

documentroot: /home/your-cpanel-user/public

Then rebuild your Apache config file


Run a config test

apachectl -t

If you get Syntax OK, then restart Apache:

systemctl restart httpd

Hope that it helps.