Create new subdomain based on user info using PHP


Site scenario: user register/sign up my site then a subdomain will automatically be created based on their username [for example]. How can I make this automatically when user sign-up? I like to use only one instance of files of my site but many subdomains. Then how can I display user specific data…May be I can extract the first portion and get the username and fetch the data based on username…

How can i achieve this: files only in one directory but many subdomains created automatically and utilize the same files?

FYI I checked the post at
but still not clear.


Anyone there be able to help on this issue?

From what I know (and maybe wrong), its 2 part process. Main part is that you need to somehow configure your webserver to “listen” to this new domain. There are 2 ways:

  • Enable wildcard domain for your site (* This will make sure that any domain is redirected to the same site (so you can have and from there you figure out the subdomain using apache and get username.

  • You add a line to httpd.conf to create a new vhost for every user. Coding aspects is still the same as first option.

The question now, I guess, is whether you know Apache or not? (assuming you have apache as your webserver).

Thanks for ur response. I appreciate it.

I already get the answer, sorry unable to notify :slight_smile: