views:

446

answers:

4

Hi guys, i know almost anything about sub-domains and dns records. i have heard about them and i know just the basics.

Actually, on my server, i do create the subdomain under plesk and then contact my hosting to create the right dns. and in 1-2 days the subdomain is reachable from everywhere (plesk can manage dns automatically, i know, but becose i dont know how does dns exactly works, i prefer to let my hoster handle them)

But.. when you do register on wordpress.com, posterous.com, etc, they create a subdomain like http://yourname.service_name.com that is ready in few seconds.. how?

I know this could be an question hardly to response because my ignorance i dont know how to formulate the question better -.-

Oh, if it can help, my environment must be linux (debian actually)

A: 

Wordpress doesn't create subdomain, it even can't create it since this is a part of apaches virtual host configuration files.

The only way to make subdomain is to create another virtual host record, add it to the DNS record, but that takes 24 hours to refresh DNS servers. Plesk and other control panels can manage that, but Wordpress can't since it's only PHP script which probably doesn't even have permissions to do that kind of stuff. Besides, you don't specify where you configuration file is, so Wordpress can't know where virtual host are :)

Please tell us more about that Wordpress subdomains, where you create them etc.

usoban
I know that is not wordpress (as php cms) itslef managing the subdomain, im interessed to the engine behind it that do the magic ;)
DaNieL
If I understand correctly, he means wordpress.com the service, not wordpress the CMS.
sjstrutt
Anyway, with the wordpress example, if you register on wordpress.com they will give you a blog under http://thenameyouchose.wordpress.com.. blogspot do the same, liveournal, etc...
DaNieL
Well, then they use wildcard subdomains as mentioned above and then backend handles the translation.
usoban
+1 simply because the answer is perfectly correct. This is the question that was unclear.
bortzmeyer
+9  A: 

Most people achieve this by using a Wildcard DNS Record, this gives the appearence of creating subdomains instantly.


Once you've got a wildcard DNS setup like this:

 *.example.com          A     77.75.105.197

You need to tell Apache you want all sub domains to be caught by a virtual host, you can do this with ServerAlias:

ServerAlias *.example.com

In PHP you can then look at $_SERVER["SERVER_NAME"] to figure out what subdomain has been used to access the virtual host, you can then have subdomain specific code/content.

Luke Antins
Ok. maybe i've understood.. something about it ;)Seem like i have to contact my hoster to implement this solution, im sacred to do mess managing things that i dont know how ^^
DaNieL
My understanding of Plesk is you could add the wildcard DNS record using the web interface, but you'd need to edit the apache config by hand to add the ServerAlias. Your hosting provider shouldn't have a problem hooking this up for you =)
Luke Antins
+2  A: 

Here's the way pastebin.com does this:

  • wildcard DNS record points all subdomains at the webserver IP
  • apache will send all requests for "unknown" domains to the first virtual host - you make the code on that host capable of doing something interesting with the domain name (in PHP, this is presented as $_SERVER['HTTP_HOST']

That way, no DNS or Apache re-configuration is required.

Paul Dixon
A: 

Also please note that you can via. Apache set it up so it uses a regular expression on the incomming hostname and through this set document root to be something like:

/var/www/topleveldomain.com/subdomain/wwwroot

This can give the illusion that there's been change in config files and all that black magic to allow mysubdomain.topleveldomain.com to become a new subdomain just by creating a folder in the right place.

Also note, this goes with the star aliasing in the DNS record.

However, I doubt that's how wordpress does it and the way Paul Dixon mentions is probably more likely.

kastermester