Server Fault is a question and answer site for system and network administrators. 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

I have a website where I want users that sign up to get their own subdomain. This subdomain is virtual, and every subdomain uses the same web server files.

I use PHP and Apache, and I know about Virtual Hosts, but I'm wondering where I need to put the vhosts code. First, I don't have access to httpd.conf. Second, I want this to be done automatically upon registration.

I've read about virtual hosts, but didn't find anything that answers my questions. Where do I add this code, and can I do it without having access to anything other than the webserver folder (not Apache?)

share|improve this question

Putting the vhosts code in the root .htaccess file might do the trick.

share|improve this answer

You can't configure a true virtual server without access to the httpd.conf file or some included file, as virtual hosts have to be configured in a server context, which means that they cannot go into .htaccess.

However, you could configure a default virtual server, and handle the virtual server code within your website. It's a much worse way of doing it, but it would work.

share|improve this answer
Just had a chat with my host. They support wildcard DNS. Then with a little PHP I can get the sub domain using $_SERVER['HTTP_HOST']. – Ronny-André Bendiksen Dec 3 '09 at 20:23

I assume that since you don't have access to httpd.conf, you are on a webhost. Ususally they have an option to redirect all subdomains to a single site. By storing the provisioned subdomains in a database, and using the same set of files, you can use the $_SERVER['HTTP_HOST'] variable as gorilla suggested to display the correct content. I have used this in the past to show multiple blogs without having to modify DNS or Apache configuration. The caveat to this is that it requires that it be supported by your webhost.

The actual configuration consists of a DNS record like the following:

* 14400 IN A

and a httpd.conf (possibly .htaccess, never tried) configuration that does not check the subdomain. Ex:

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