Changing the primary (main) domain on a cPanel account looks like editing one field, but it touches more than any other account edit: the document root, the Apache virtual host, the DNS zone, mail routing, and every place the old domain name was embedded. WHM does the core rewrite cleanly through Modify an Account, but it does not chase down the SSL certificate that still names the old domain, the email accounts that lived on it, or the application configs that hard-coded it. Knowing what WHM changes — and what it leaves for you — is the difference between a clean rename and a half-broken account.
What’s happening
The primary domain is the account’s identity: it is the name on the main virtual host, the default DNS zone, and the basis of the home directory’s public_html. WHM » Account Information » Modify an Account lets you change it. When you do, cPanel renames the primary virtual host to the new domain, creates a DNS zone for the new domain (and can remove or keep the old one), updates /etc/userdomains and the user’s userdata, and rebuilds Apache. The account username does not change — cPanel does not rename users — only the domain attached to it.
What the rewrite does not do is follow the domain into everything downstream. The SSL certificate on the old vhost still lists the old domain; the new domain has no cert until AutoSSL re-issues or you install one, so HTTPS breaks in the gap. Email accounts were user@olddomain.com; the mailboxes still exist under the old domain’s mail directory and do not automatically become user@newdomain.com. Anything that hard-codes the domain — a WordPress siteurl, a CMS config, absolute links in the database, cron jobs calling the old hostname — keeps pointing at the old name. And DNS for the new domain has to actually point at this server (its A record and, if mail stays here, MX) or the rename is cosmetic. The Modify an Account change is the start; the cleanup is what makes the new domain actually serve the site and mail.
How to verify
See the account’s current primary domain and how it is wired before changing anything:
# The account's main domain and ownership
grep -w <cpaneluser> /etc/userdomains
whmapi1 accountsummary user=<cpaneluser>
# Docroot and vhost the primary domain points at
grep -ri 'documentroot\|servername' /var/cpanel/userdata/<cpaneluser>/ | head
After the change, confirm the rewrite landed across userdata, DNS, and Apache:
# New domain now owns the account?
grep -w <cpaneluser> /etc/userdomains
ls -la /var/cpanel/userdata/<cpaneluser>/
# DNS zone for the new domain exists and points here
dig +short A newdomain.com @localhost
cat /var/named/newdomain.com.db 2>/dev/null | grep -E 'A|MX' | head
# Apache vhost rebuilt with the new ServerName
grep -A3 newdomain.com /etc/apache2/conf/httpd.conf 2>/dev/null | head
httpd -S 2>&1 | grep newdomain.com
Check the two things WHM does not fix — the certificate and the mailboxes:
# Is there a valid cert for the NEW domain yet?
whmapi1 fetch_ssl_certificates_for_fqdns domains=newdomain.com 2>/dev/null
# Mailboxes still under the OLD domain's mail dir
ls -la /home/<cpaneluser>/mail/ 2>/dev/null
The fix / steps
- Point the new domain’s DNS at this server first. Before the rename, make sure
newdomain.com’s authoritative A record resolves to this server’s IP (and MX to it, if mail will live here). Changing the primary domain to a name that does not resolve to the box gives you a vhost no one can reach. Do this and let it propagate so the new domain works the moment the account flips. - Back up the account before you change the primary domain. A primary-domain change rewrites vhost, DNS, and userdata; if an app has the old domain baked in, the site can break in ways that are easier to recover from a backup than to unwind by hand. Take a fresh account backup (or at least a config snapshot) first — this is a structural edit, not a cosmetic one.
- Change it in WHM » Modify an Account. Open Modify an Account, select the user, and set the new Primary Domain. Save and let cPanel rebuild — it renames the main vhost, creates the new DNS zone, updates
/etc/userdomainsand userdata, and restarts Apache. Decide whether to keep the old domain (as a parked/addon domain) or let it go; keeping it preserves old links and mail during a transition. - Re-issue or install SSL for the new domain. The new domain has no certificate until you provide one. Run AutoSSL for the account (WHM » Manage AutoSSL » Run AutoSSL, or per-account in cPanel) so it issues a cert covering the new domain, or install a purchased cert. Until this completes, HTTPS to the new domain fails with a name mismatch — verify with the cert check above before declaring the rename done.
- Re-create or migrate the email accounts. Mailboxes that were
user@olddomain.comdo not becomeuser@newdomain.comon their own. If mail should move to the new domain, create the addresses under the new domain in cPanel » Email Accounts and migrate the mail (the old Maildir is under/home/<cpaneluser>/mail/olddomain.com/). If the old domain is kept, the old addresses keep working — decide deliberately which domain owns mail going forward. - Fix applications that hard-coded the old domain. A WordPress, Joomla, or custom app stores its URL internally. Update WordPress
siteurl/home(viawp-config.php, the database, or WP-CLI), run a search-replace for absolute links in the database, and update any CMS or app config that names the old domain. The site can load blank or redirect-loop to the old domain until these are changed. - Update cron jobs, redirects, and external references. Cron entries that curl the old hostname,
.htaccessredirects written for the old domain, and external services (payment webhooks, API callbacks, DNS at other providers) that point at the old name all need updating. Search the account for the old domain string and fix each occurrence — these are the references WHM has no way to know about. - Verify the site and mail end to end on the new domain. Load
https://newdomain.comand confirm a valid certificate and the right site (not a redirect to the old name), then send a test to and from a new-domain mailbox and watchtail -f /var/log/exim_mainlog. A primary-domain change is only complete when the new domain serves the site over HTTPS and handles mail — confirm both, not just that WHM reported success.
A primary-domain change is done when the new domain resolves here, serves the site over valid SSL, carries mail, and no app or cron still names the old domain. Stack Harbor handles cPanel primary-domain changes and the cleanup they require under cPanel server management — start a conversation before renaming a live account.