Skip to content

Changing a domain's document root on cPanel safely

How to point a domain at a different folder on cPanel — for the primary, addon, or subdomain — and the gotchas that break sites when the docroot moves.

Changing a domain’s document root — the folder Apache treats as the top of the site — comes up constantly: moving a site out of a subfolder, pointing a domain at a framework’s public/ directory, or consolidating after a restructure. cPanel makes this straightforward for addon and subdomains and slightly more involved for the primary domain. The work is not just editing one value; the SSL vhost, any .htaccess rewrite base, and the application’s own path assumptions all have to follow the move, or the site breaks the moment Apache reloads.

What’s happening

Every domain has a DocumentRoot in its Apache vhost. For the primary domain it is fixed at /home/<cpaneluser>/public_html; for addon domains and subdomains cPanel lets you choose the folder, stored in /var/cpanel/userdata/<cpaneluser>/<domain>. Changing it tells Apache to serve a different folder for that hostname.

A few things make this more than a one-line change. Apache maintains a separate vhost for SSL (port 443), so the docroot must change in both the HTTP and HTTPS vhosts — cPanel handles this when you use its tools, but a hand-edit of httpd.conf that misses the SSL vhost leaves HTTPS pointing at the old folder. Many frameworks (Laravel, Symfony) want the docroot at a public/ subfolder, not the project root, so the choice of folder is deliberate. And applications that store absolute paths or a RewriteBase need those updated to the new docroot. cPanel’s primary-domain docroot is intentionally hard to change in the UI because so much keys off it; the supported path is to relocate via the right tool rather than editing httpd.conf directly.

How to verify

Confirm the current document root and that you are editing the right domain.

# Current docroot cPanel has for the domain
grep -i "<domain>" /etc/userdatadomains
cat /var/cpanel/userdata/<cpaneluser>/<domain> | grep -i documentroot
cat /var/cpanel/userdata/<cpaneluser>/<domain>_SSL | grep -i documentroot 2>/dev/null

# Confirm the target folder exists and has the site
ls -la /home/<cpaneluser>/public_html/<new-folder>/

After the change, verify both the HTTP and HTTPS vhosts moved and the config is valid.

# Both vhosts should show the NEW docroot
grep -A3 -i "ServerName <domain>" /etc/apache2/conf/httpd.conf | grep -i documentroot

# Validate before reloading
apachectl configtest

# Confirm what Apache serves after reload
curl -sI -H "Host: <domain>" http://127.0.0.1/ | head -1

The fix

  1. For an addon domain or subdomain, edit it in cPanel — cPanel » Domains lists each domain with its document root; newer cPanel versions let you edit the docroot inline. Set it to the new folder, which cPanel writes to both the HTTP and SSL vhosts and rebuilds Apache for you. This is the supported, safe path for non-primary domains.
  2. For the primary domain, relocate rather than retarget — cPanel deliberately fixes the primary docroot at public_html. Rather than fighting it, put the site’s files in public_html (or point public_html content at the subfolder via a small .htaccess rewrite, or symlink), or change the account’s primary domain. Editing httpd.conf to move the primary docroot is not upgrade-safe — cPanel regenerates the file.
  3. Point a framework at its public/ folder — for Laravel/Symfony, set the docroot to .../project/public. Keep the rest of the project (vendor, .env, app code) outside the docroot so it is not web-accessible. This is the correct, secure layout — never set the docroot to the project root.
  4. Move the SSL vhost too — if you do edit config by hand (last resort), change the docroot in both the :80 and :443 vhosts. A common breakage is HTTP working on the new folder while HTTPS still serves the old one because only one vhost was updated.
  5. Update the application’s stored paths — an app with a hard-coded absolute path or a RewriteBase referencing the old docroot will break. Update wp-config.php paths, the framework .env, and any RewriteBase to the new location (see the .htaccess and site-broken runbooks). Regenerate WordPress permalinks after the move.
  6. Rebuild and validate Apache — after any docroot change made outside the UI, run /scripts/rebuildhttpdconf, apachectl configtest, then /scripts/restartsrv_httpd. The configtest catches a typo before it takes the site down; the rebuild ensures the change persists across cPanel’s own regeneration.
  7. Check permissions on the new folder — the new docroot and its contents must be owned by the cPanel user with 0755 directories / 0644 files, or you trade a working site for a 403 (see the permissions runbook). A freshly created target folder sometimes lands with the wrong owner.

After the change, load the domain and confirm curl -sI -H "Host: <domain>" returns the new site over both HTTP and HTTPS with a clean configtest — verifying both schemes is what proves the SSL vhost moved with the HTTP one, the step most hand-edits miss. Stack Harbor handles cPanel document-root changes under cPanel/WHM management — start a conversation.