Two tricks to setting up subdomains with Apache:
1) Make a wildcard *.domain entry in your DNS server’s A record.
2) In httpd.conf, define your subdomains before your main site in the list of vhosts. This way the definition for your *.domain becomes the fall-through / catch-all for any request that does not prepend foo.domain. If you define the main site first with *.domain, it will catch all requests, and the subdomains will never be handled.