0

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?)

rebellion
  • 101
  • 2

3 Answers3

1

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

Joshua
  • 593
  • 2
  • 19
1

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.

gorilla
  • 1,207
  • 9
  • 6
  • 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']`. – rebellion Dec 03 '09 at 20:23
0

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
Mitch
  • 2,363
  • 14
  • 23