Changing the DocumentRoot (Root Directory) in cPanel – 2025 Guide
For projects using frameworks like Laravel, you may need to change your domain’s root directory from the defaultpublic_html to public_html/public. Follow the steps below to easily complete this process.🔧 1. Connect via SSH and Edit the Configuration File
To access your server via SSH, open your SSH client and run the following commands:
Bash:
cd /var/cpanel/userdata/USERNAME/
nano DOMAIN.COM
- Replace
USERNAMEandDOMAIN.COMwith your actual account information.
Find the following line in the file:
YAML:
documentroot: /home/USERNAME/public_html
Change it to:
YAML:
documentroot: /home/USERNAME/public_html/public
To save and exit: press
CTRL + X, then Y, and finally Enter.🔁 2. Run the Commands to Apply the Changes
Execute the following commands in order:
Bash:
/scripts/updateuserdomains
/scripts/updateuserdatacache
mv /etc/apache2/conf/httpd.conf{,.bk}
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd
Don’t forget to run the commands in the exact order listed above!