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?

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 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.


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'));  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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