Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 About.com create all the subdomains they use. Is it manually, or some other way?

share|improve this question

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 hostname.yourdomain.com is set to your webserver e.g.:

*.example.com IN A

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

Your Apache vhost needs to accept every hostname of the domain

ServerName example.com ServerAlias *.example.com

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 https://github.com/CpanelInc/xmlapi-php.

You then invoke it like this:

 require("xmlapi.php"); // this can be downloaded from https://github.com/CpanelInc/xmlapi-php/blob/master/xmlapi.php
$xmlapi = new xmlapi("your-primary-domain.com");   
$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('subdomain.domain.com',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.