I've noticed some hosting providers have Apache setup so that if I create a directory (foo.example.com) Apache will automatically know that the DNS entry for foo.example.com routes to that document root.

Where the DocumentRoot would match based on the pattern from the ServerName wild card.

In doing so all I should need to do is create /home/user/foo.example.com after the configuration is in place and not need to modify anything in Apache. This would allow me to add sub-domains on the fly without needing to restart or reload or even edit anything in Apache.

Last website company i worked with did something similar, instead of hardcoding it in the apache configuration, we wanted to store the configuration in the database, allowing us to update it any time we want and it would adjust whenever we needed.

I personally am against storing configuration in databases. Flat files seem superior! What if the database crashes, etc? I appreciate the answer but this isn't exactly what I'm looking for.
–
Marco CeppiAug 6 '11 at 0:17

1

It all depends on your point of view. What if Apache crashes,etc? Or what if too many typos are made in flat files? One size does not fit all.
–
AaronAug 6 '11 at 3:16

If not a database, then could this be modified to use XML or another structured format? (But then, wouldn't that be just as complicated and inflexible as httpd.conf?)
–
Stefan LasiewskiAug 6 '11 at 3:44

I guess I don't have enough karma to add a comment, so I will add an answer. Steve Madden's answer is correct.

If you want to create a development domain on your local machine (e.g. mycomputer.dev), you can use the VirtualDocumentRoot trick along with running a local DNS server to do so. Then, when you want to start a new website, just create the directory. No editing of Apache, no editing of hosts files, no Apache restart.

No I want to be able to create bar.example.com, baz.example.com, etc on the fly without changing apache. Hence why the wild card is in the documentroot definition as well. I've seen (mt) do this on their GridServer service. Curious if it's possible.
–
Marco CeppiAug 5 '11 at 23:09