The document root is the directory where cPanel serves your website files from. By default, this is the public_html folder, but you may need to change it when installing applications that require custom directory structures, running multiple site versions or organising files differently.
You will learn three methods to change the document root: configuring addon domains, creating symbolic links via SSH and using .htaccess redirects. Each approach suits different scenarios, from simple domain additions to advanced server configurations.
Changing the document root allows you to serve website content from a location other than the default public_html directory. This flexibility supports several common scenarios that standard cPanel configurations cannot accommodate.
Third-party applications often require specific directory structures that conflict with cPanel defaults. URL shorteners, for example, typically need to operate from the root domain rather than a subdirectory. Development and staging environments benefit from separate document roots that isolate test code from production files. Custom site structures that organise content by project, client or application type also require non-standard directory configurations.
Addon domains in cPanel allow you to host multiple websites under one account. When creating an addon domain, you can specify a custom document root location instead of accepting the default directory structure.
yourdomain.co.uk:2083 and entering your credentials.

Your addon domain now serves content from the specified directory. This method works best when adding new domains rather than modifying existing ones, as it handles DNS configuration and directory creation automatically.
Symbolic links redirect one directory to another at the filesystem level. This approach maintains the appearance of serving files from public_html whilst actually loading content from a different location. It proves useful when applications expect files in specific directories but you need to store them elsewhere.
tar -cvzf public_html_backup.tar.gz public_html
mv public_html public_html_old
public_html location. Replace /path/to/directory with your actual target directory and username with your cPanel username.ln -s /path/to/directory /home/username/public_html
chmod -R 755 /path/to/directory
find /path/to/directory -type f -exec chmod 644 {} \;
The symbolic link now redirects all requests for public_html to your specified directory. This method preserves cPanel’s expectation of a public_html folder whilst giving you flexibility in where files actually reside.
.htaccess redirects tell Apache to serve content from a different directory without changing the filesystem structure. This approach works when you cannot or prefer not to modify directories directly, though it adds a small processing overhead to each request.
public_html in the directory tree. This is typically where your .htaccess file resides.
.htaccess and select Edit. If the file does not exist, create it by clicking File in the toolbar and entering .htaccess as the filename.domain.tld with your actual domain and /path/to/directory with your new document root location.RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
RewriteRule ^(.*)$ /path/to/directory/$1 [L]
Apache now redirects all requests to your specified directory. This method requires no filesystem changes and works across different hosting environments, though it processes the redirect on every page load rather than at the system level.
The primary domain on a cPanel account uses a document root that cannot be changed through the standard interface. This restriction exists because the primary domain ties directly to the account’s core configuration files. Modifying it incorrectly can break email delivery, SSL certificates and other account-level services.
Non-root users must request support intervention to change the primary domain’s document root. If you have root access to your server, you can modify the configuration files directly through SSH.
Contact our support team with your requested document root path. Our team will update the configuration files and verify that all account services continue functioning correctly after the change.
Root access allows you to edit the user data files that define document root locations. This process requires careful attention to detail, as errors in these files can prevent websites from loading.
username with the cPanel account username and domain.tld with the actual domain name.nano /var/cpanel/userdata/username/domain.tld
nano /var/cpanel/userdata/username/domain.tld_SSL
Ctrl+W in nano to open the search function. Type documentroot and press Enter. This jumps to the line you need to modify.Ctrl+X, then Y to confirm, then Enter to save. Repeat this process for both the standard and SSL configuration files.rm -vf /var/cpanel/userdata/username/domain.tld.cache
rm -vf /var/cpanel/userdata/username/domain.tld_SSL.cache
/scripts/updateuserdatacache && /scripts/rebuildhttpdconf && service httpd restart
The primary domain now serves content from your specified directory. Monitor email delivery and SSL certificate functionality over the next few hours to ensure the change did not affect other account services.
Document root changes can cause several common issues if directories, permissions or configurations are incorrect. These problems typically manifest as blank pages, permission errors or missing content.
Apache cannot access the new document root directory. This usually indicates incorrect permissions or ownership on the target directory.
ls -laThe website loads but displays without styling or images. This indicates that static files have incorrect permissions or the document root path points to a directory missing these assets.
The symbolic link creates a loop where the target directory points back to itself or another symlink. This prevents Apache from resolving the actual file location.
ls -la to verify the symlink points to the correct absolute pathrm public_html and recreate it with the correct pathIf errors persist after checking these common issues, review our guide on troubleshooting website error codes for detailed diagnostic steps.
Document root changes form part of broader server and file management practices. Understanding related concepts helps you make informed decisions about directory structures and avoid common configuration mistakes.
File permissions and ownership determine which users and processes can access directories. The chown command changes file ownership, whilst chmod modifies permission levels. Both commands prove essential when troubleshooting access issues after document root changes. Apache’s documentation on URL mapping explains how the web server translates URLs to filesystem paths, clarifying why document root location matters for site functionality.
Server restarts become necessary when configuration changes do not take effect immediately. Our guide on restarting Apache covers when and how to restart the web server safely. For VPS users managing multiple sites, understanding these concepts allows you to structure hosting environments that balance organisation with performance.
You now know three methods to change the document root in cPanel. Addon domains work best for new sites, symbolic links maintain compatibility with applications expecting standard paths and .htaccess redirects offer a lightweight alternative when filesystem changes are not possible. Root users can modify primary domain configurations directly through SSH.
Test your site thoroughly after making document root changes. Verify that all pages load correctly, forms submit successfully and SSL certificates continue working. Check file permissions if you encounter access errors. Our cPanel hosting includes full SSH access and file management tools for flexible directory configuration.
If you run into any trouble, get in touch and our team will be happy to help.
Launch your website with our reliable cPanel hosting with unlimited bandwidth and expert support.
Get cPanel Hosting