How to Change the Document Root for Your cPanel Primary Domain Name

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 straight forward. 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:
/var/cpanel/userdata/your-cpanel-user/your-domain.com
-
- Modify the documentroot accordingly:
documentroot: /home/your-cpanel-user/public_html
-
- Then rebuild your Apache config file
/scripts/rebuildhttpdconf
-
- Run a config test
service httpd configtest
-
- If you get
Syntax OK
, then restart Apache
- If you get
service httpd restart
This is pretty much it. Hope that it helps.
Recent Posts

How DigitalOcean Simplifies Cloud Computing for Developers
2023-01-18 12:35:28
How to Get Current Route Name in Laravel
2020-11-08 08:57:11
How to check the logs of running and crashed pods in Kubernetes?
2020-10-28 09:01:44
Top 10 VScode Shortcuts For Mac and Windows to Help You be More Productive
2020-10-28 07:12:51