Change Document Root for Main Domain in cPanel

On cPanel & WHM version 136 or later, use the WHM API function built for this. This function changes the document root for a cPanel account’s primary domain. Call it like this: cpanel

whmapi1 set_primary_domain_docroot username=USERNAME docroot=public_html/myapp/public

Before you run it, note:

  • The path must begin with public_html/, and the target directory must already exist. cpanel
  • This function does not move any files, so put your site in the new folder first. cpanel
  • Any parked domains (ServerAlias entries) on the affected domain will inherit the new document root. cpanel
  • AutoSSL HTTP-01 renewals will fail if the new document root is empty or missing at renewal time. cpanel
  • To undo it, run the same command with the original path.