Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

How can one create a new subdomain using a script? Creating a new database or database table is something I'm familiar with.

If this is not possible, how does create all the subdomains they use. Is it manually, or some other way?

share|improve this question

2 Answers 2

What exactly do you mean by subdomain? Just the entry in the DNS System or the whole handling of the subdomain (which is just a hostname).

You can set a wildcard DNS entry so every is set to your webserver e.g.:

* IN A

so would be resolved to except you specified a entry for the URL.

Your Apache vhost needs to accept every hostname of the domain

ServerName ServerAlias *

Everything else is handled by .htaccess files using mod_rewrite and PHP routers.

share|improve this answer

If you are using cPanel you can use the xmlapi class

You then invoke it like this:

 require("xmlapi.php"); // this can be downloaded from
$xmlapi = new xmlapi("");   
$xmlapi->set_port( 2083 );   
$xmlapi->password_auth('username','password');   //cpanel credentials 
$xmlapi->set_debug(0);//output actions in the error log 1 for true and 0 false 

// create subdomain
print $xmlapi->api1_query('accountname','SubDomain','addsubdomain',array('',0,0,'/public_html/location.of.the.web.files'));  
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.