How to create subdomains for domains bought via Google Apps (Enom)

This was supposed to be the easiest thing (as in CPanel – goto Subdomains, click create a new subdomain, specify a directory and you’r done!)… but allas! It took me a full day to figure this out :(
I’m sad…

Anyways… as Enom’s Domain control panel is, there is no way of doing this. All you can do, is create A/CNAME/Redirection/TXT records. Ofcourse, they are not providing the hosting… so them knowing about the directory structure is perfectly – a valid problem.

After conversing with Enom’s helpful support staff (in near realtime), I was able to solve the problem…

Problem
But then, how do you create a subdomain on a domain which is bought via Google Apps and who’s DNS is managed by Enom?

Assumptions

  • You want to create a subdomain test.example.com
  • You have a r00t access
  • You are using Ubuntu with Apache2
  • Your example.com resolves to 1.2.3.4

Solution
At Enom control panel – add an “A” record with the value of 1.2.3.4 (address field) and “test” as hostname field (without the “”) and save.

At your hosting server end…
Apache2 needs to be told to create a VirtualHost for your subdomain
Your /etc/apache2/sites-available/example-com file (example-com is just a random name, replace it with your virtual hosts file name) should look like

NameVirtualHost *:80

<VirtualHost *:80>
ServerName example.com
DocumentRoot /my/document/root
</VirtualHost>

<VirtualHost *:80>
ServerName test.example.com
DocumentRoot /my/document/root/test
</VirtualHost>

Restart apache2 and you’r done!
Wait for a few minutes for the changes to propogate… and try hitting http://test.example.com in your browser.

Good Luck!

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  • http://www.apnabill.com Mayank Jain (makuchaku)

    Ofcourse, once you host a rails app in a subdomain, you no longer need the following directive in your config/environment.rb file
    config.action_controller.relative_url_root = “/dev”