How to change the default document root in cPanel shared hosting
This guide shows you how to move the default website files from the standard public_html location to a custom directory on cPanel 118.x shared hosting accounts. Follow these steps to update your document root settings safely.
You will change the default document root for a cPanel account to a custom directory instead of the standard public_html. These steps apply to cPanel 118.x on standard shared hosting environments. You must have root or reseller access to modify these settings.
Prerequisites
- Root access to the server or Reseller access to the specific cPanel account.
- SSH access to the server or WHM access to the account.
- A custom directory created outside the standard public_html folder.
- Backup of the current public_html contents before moving files.
- cPanel version 118.x or later installed on the server.
Step 1: Create the new document root directory
Create a new directory that will serve as your custom document root. This directory must be empty or contain only the files you want to serve. Use SSH to create the directory at the root level or within the user's home directory.
mkdir -p /home/<username>/custom-web-root
Replace <username> with the actual cPanel account username. This command creates a new folder named custom-web-root inside the user's home directory. Ensure you have write permissions for this directory.
drwx------ 2 <username> <username> 4096 Jan 15 10:30 /home/<username>/custom-web-root
The output shows the new directory with restricted permissions. If you see an error like Permission denied, ensure you are logged in as root or have the necessary privileges.
Step 2: Move the current public_html contents
Before changing the document root, move the existing website files from the default public_html to the new custom directory. This prevents data loss and keeps your site accessible during the transition.
mv /home/<username>/public_html/* /home/<username>/custom-web-root/
This command moves all files from the old public_html directory to the new custom-web-root. If the directory is empty, the command may fail silently. Check the new directory to confirm the files moved successfully.
total 12
drwxr-x--- 3 <username> <username> 4096 Jan 15 10:30 .
drwxr-x--- 4 <username> <username> 4096 Jan 15 10:30 ..
index.html
style.css
The output lists the files now inside the new directory. If you see an error like No such file or directory, ensure the source directory exists and is not empty.
Step 3: Update the cPanel document root settings
Log in to cPanel as the account user or use WHM to modify the document root. Navigate to the Home Directory section in cPanel or use the Set Document Root feature in WHM. This step updates the server's configuration to point to the new directory.
In cPanel, go to Home Directory and click Change Document Root. Enter the new path /home/<username>/custom-web-root in the text field. Save the changes. In WHM, go to Home Directory under User Manager, select the account, and click Set Document Root. Enter the new path and save.
Document Root: /home/<username>/custom-web-root
The system updates the Apache or OpenLiteSpeed configuration to serve files from the new location. A server restart may be required for the changes to take effect immediately.
Verify the installation
Test the new document root by accessing the website URL in a browser. The site should load without errors, and the files should be served from the custom directory. Use the following command to check the current document root in cPanel:
cpanel --zone=user --zoneoutput=users --user=<username> --print=home
The output should show the new document root path:
Home Directory: /home/<username>/custom-web-root
If the path matches your custom directory, the configuration is correct. If the site still shows the old path, restart Apache or OpenLiteSpeed using systemctl restart httpd or systemctl restart lsws as appropriate.
Troubleshooting
If the website does not load after changing the document root, check the error logs for permission issues or misconfigurations. Common problems include incorrect directory permissions or missing files in the new location.
- Ensure the new directory has the correct permissions:
chown <username>:<username> /home/<username>/custom-web-root. - Verify that the
index.htmlfile exists in the new directory:ls -la /home/<username>/custom-web-root/. - Check the Apache error log for syntax errors:
tail -f /var/log/apache2/error.log. - Restart the web server to apply changes:
systemctl restart httpdorsystemctl restart lsws. - If using OpenLiteSpeed, verify the configuration file at
/usr/local/apache/conf/httpd.confpoints to the new directory. - Ensure no other virtual hosts are pointing to the old public_html path.
If the site still fails to load, contact your hosting provider's support team for assistance. They can verify the server configuration and resolve any backend issues.