Take the 2-minute tour ×
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 About.com 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 hostname.yourdomain.com is set to your webserver e.g.:

*.example.com IN A 123.123.123.123

so everything.example.org would be resolved to 123.123.123.123 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

 
discard

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.