Create sub-domain in CPanel via UAPI from WordPress

c3PanoH

Member
Apr 16, 2020
10
1
3
UK
cPanel Access Level
Root Administrator
Earlier this year i enquired on this forum about achieving what the thread title explains. I've since realised i need better hosting or so i think. I'm just about to ditch my current host and finda good budget VPS preferably managed as im not a Linux Guru. Can anyone explain what Features i need in respect to the question asked here, namely what versions of CPanel API and do i need CPanel and whm API? I know the new UAPI is recommended but I've since heard that you can perform sub-domain creation from external scripts like PHP without cpanel/whm 'root' access. The following answer snippet quoted from Stack Overflow :

"...You're likely better off using an API token if your host will create one for you...according to the docs, the API token replaces the need for root access entirely ..."

If this is indeed the case then this would solve a lot of headaches since most 'managed' VPS packages that provide root access are out of my budget range.

Any help, very much appreciated.
 

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,607
80
458
cPanel Access Level
Root Administrator
Hi c3PanoH,

You should be able to automate subdomain creation with a cPanel account. A limitation is the subdomains can only be created on the cPanel account. Account Sally cannot create subdomains on account Fred, for example. If you need to create subdomains on other accounts, or the server hostname, then you'll likely need a VPS as those abilities are not available to a cPanel account.

If a cPanel account works, then you'll need: a cPanel account with access to the Subdomains feature. That feature gives you access to the SubDomain::addsubdomain API call (UAPI Functions - SubDomain::addsubdomain - Developer Documentation - cPanel Documentation). The cPanel UI uses the same API calls that your script would use.
 

c3PanoH

Member
Apr 16, 2020
10
1
3
UK
cPanel Access Level
Root Administrator
Hi c3PanoH,

You should be able to automate subdomain creation with a cPanel account. A limitation is the subdomains can only be created on the cPanel account. Account Sally cannot create subdomains on account Fred, for example. If you need to create subdomains on other accounts, or the server hostname, then you'll likely need a VPS as those abilities are not available to a cPanel account.

If a cPanel account works, then you'll need: a cPanel account with access to the Subdomains feature. That feature gives you access to the SubDomain::addsubdomain API call (UAPI Functions - SubDomain::addsubdomain - Developer Documentation - cPanel Documentation). The cPanel UI uses the same API calls that your script would use.
Hi cPanelKenneth,
Thats great, just what i was looking for - good job i didn't sign up for a VPS yesterday, phew! - what you suggest fits my scenario exactly - i have CPanel at my disposal as adminstrator at the highest level you can have on a share hosting account; if i need to step up to a reseller account then i could do that too. All i need to do is what ive been doing manually so far, namely when i get a new sign up on my site i simply create a new subdomain which will use my main domain as the root
i.e. a-new-subsite.maindomain.com - maindomain.com being my primary domain with my hosting provider and i'm the only cPanel user.

If i needed to step up to a reseller account then id be OK doing that since i could easily integrate WHM/WHMCS later on to enhance my project.

Just curious : many web hosts allow you to create more than one website and have multiple domain names on the same hosting account so, to use your example, if account-Sally and account-Fred both belonged to me under my cPanel account could i then create sub-domains on Fred from account-Sally?
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
I am sorry about the delay in this.
Just curious : many web hosts allow you to create more than one website and have multiple domain names on the same hosting account so, to use your example, if account-Sally and account-Fred both belonged to me under my cPanel account could i then create sub-domains on Fred from account-Sally?
So lets say that you don't have account-Sally and account-Fred since if they existed on your cPanel account they wouldn't be separate accounts. Let's say instead you have added Sally.tld and Fred.tld as addon domains. Once that's complete yes you could most certainly create subdomains for them.
 

c3PanoH

Member
Apr 16, 2020
10
1
3
UK
cPanel Access Level
Root Administrator
I am sorry about the delay in this.

So lets say that you don't have account-Sally and account-Fred since if they existed on your cPanel account they wouldn't be separate accounts. Let's say instead you have added Sally.tld and Fred.tld as addon domains. Once that's complete yes you could most certainly create subdomains for them.
Hello thanks for the response,

So in my new hosting plan they describe Hosted Domains as "The Number of domains with their own web sites, email accounts and DNS records that you may host under your cPanel account." - please excuse my ignorance, are they referring then to 'addon-domains'
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,300
363
Houston
Sort of, Domains can be subdomains, addon domains or alias domains. They're referring to all three I believe.

You could argue that alias domains don't technically have their own site but they could have their own email accounts and DNS records.
 

c3PanoH

Member
Apr 16, 2020
10
1
3
UK
cPanel Access Level
Root Administrator
Sort of, Domains can be subdomains, addon domains or alias domains. They're referring to all three I believe.

You could argue that alias domains don't technically have their own site but they could have their own email accounts and DNS records.
Ok, got it so more choices then since most hosts provide most of these.
Thanks for that Lauren - i'll consider the thread closed now

Bye