Automatic Create Subdomain - www.cpanelusername.hostname

jaro74

Member
Oct 10, 2010
15
0
51
Whether it is possible to automatically create subdomain like "www.cpanelusername.hostname" when i create new account for client. Can it be done in cPanel DNS zone template?

Please help

My DNS zone template

Code:
; cPanel %cpversion%
; Zone file for %domain%
$TTL %ttl%
@      %nsttl%	IN      SOA     %nameserver%. %rpemail%. (
		%serial%	; serial, todays date+todays
		86400		; refresh, seconds
		7200		; retry, seconds
		3600000		; expire, seconds
		86400 )		; minimum, seconds

%domain%. %nsttl% IN NS %nameserver%.
%domain%. %nsttl% IN NS %nameserver2%.
%domain%. %nsttl% IN NS %nameserver3%.
%domain%. %nsttl% IN NS %nameserver4%.

%nameserverentry%. IN A %nameservera%
%nameserverentry2%. IN A %nameservera2%
%nameserverentry3%. IN A %nameservera3%
%nameserverentry4%. IN A %nameservera4%

%domain%. IN A %ip%

localhost.%domain%. IN A 127.0.0.1

%domain%. IN MX 0 %domain%.

mail IN CNAME %domain%.
www IN CNAME %domain%.
ftp IN CNAME %domain%.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
You could use a /scripts/postwwwacct script to automatically create a subdomain for the account on account creation. This would likely be easier to perform than trying to modify the zone template to add that domain, because the zone templates do not recognize the cPanel username as a field type.
 

jaro74

Member
Oct 10, 2010
15
0
51
and whether it is possible add other parameter(field name) to dns zone template to auto create subdomain?

in place subdomain add clientdomainname without dots


example clientdomainname.tld >>>>>> clientdomainname.hostname ?

the point is that the client using a temporary subdomain before park domain own domain
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
The issue here is that the %domain% entry contains the tld in it such as .com or .net or whatever it might be, so you cannot simply do:

%domain%.server.domain.com.

Where server.domain.com represents the hostname. The better option is truly to use /scripts/postwwwacct to create an A record entry to point some subdomain based on variables into the zone file.
 

jaro74

Member
Oct 10, 2010
15
0
51
Can you please explain what a file /scripts/postwwwacct and how to use it. I'm new in cp . regards
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
The "/scripts/postwwwacct" script is used to automatically perform tasks after accounts are created.

This is fully documented at:

cPanel and WHM Script Hooks

Thank you.
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
The file /scripts/postwwwacct does not exist by default but is a hook you can create for using after account creation. You would need to create the script to automatically create the subdomain. That is something you should be researching as the system administrator and developer of your system. If you want to ask questions after you've researched the documentation Michael provided on code you've worked on creating, please definitely feel free to ask.

The purpose of this forum isn't to provide cut and paste examples of coding for all functions, but to point you in the direction to learn how to administer and develop specialized content for your own machine.