Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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:

*.domain.net. 14400 IN A 123.123.123.123

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

ServerAlias *.domain.net
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']. –  ronnyandre Dec 3 '09 at 20:23

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

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.