-----------------------------
The Fresh VirtualHost Entry
-----------------------------
Let's first learn the basics about how an Apache VirtualHost entry is setup. This is very important for you to understand. Let's say, for example, you signed up with your-full-name-temp.com on a shared IP and wanted to make use of our "Sneak Peek" domain feature. The first few relevant lines we'd setup for you would be this:
<VirtualHost Shared_IP_Address-->
ServerAlias your-full-name-temp.com
DocumentRoot /home/username/public_html
ServerName www.your-full-name-temp.com
ServerAlias 234user.hostname.hostingrails.com www.234user.hostname.hostingrails.com
...
-----------------------------
The Parked Domain
-----------------------------
Can you spot what the parked domain for this account is?
That's right! If you pointed your browser to 234user.hostname.hostingrails.com it would serve up the files located at /home/username/public_html
When you create a 'Parked Domain' via cPanel, it simply adds a ServerAlias to the VirtualHost entry for the target domain. Thus, in the above example, 234user.hostname.hostingrails.com is said to be "parked over" your-full-name-temp.com
You can add as many parked domains as you want, which is useful for single applications like Mephisto than can handle multiple domains.
-----------------------------
The Subdomain
-----------------------------
When you create a subdomain in cPanel, you are creating a new VirtualHost entry:
<VirtualHost Shared_IP_Address-->
ServerAlias subdomain.your-full-name-temp.com
DocumentRoot /home/username/public_html/subdomain
ServerName www.subdomain.your-full-name-temp.com
...
Thus, browsing to subdomain.your-full-name-temp.com, assuming you have it pointing to the server by now, will bring you to the files in /home/username/public_html/subdomain - if you don't have this domain pointing to the server (afterall it is a temp domain) then you can just create a parked domain over it; the parked domain should already be pointing at the server/IP for this to work)-----------------------------
The Addon Domain
-----------------------------
cPanel is smart with addon domains. These are "fully hosted" domains in every sense, as you can have mail, databases, etc... for this domain only - however the VirtualHost entry the addon domains is technically a domain parked over a subdomain:
<VirtualHost Shared_IP_Address-->
ServerAlias addondomain.your-full-name-temp.com
DocumentRoot /home/username/public_html/addondomain
ServerName www.addondomain.your-full-name-temp.com
ServerAlias addondomain.com www.addondomain.com
...
Thus, browsing to addondomain.com will bring you to the contents of /home/username/public_html/addondomain - even if your-full-name-temp.com is still a bogus domain. -----------------------------
The Art of Symlinking
-----------------------------
So here's where the beauty, ease, and flexibility of symlinking comes in. You should create all your Rails apps or non-rails websites in your root [~]
Since most people learn best by example, I'll walk you through the process of setting up two addon domains (one rails, one static) and a subdomain over an account that I signed up for with your-full-name-temp.com
- - -
Lets say in my root I have this:
addon1_rails
addon2_static
public_html
subdomain_rails
In cPanel I would go addon my domain1.com, whose DocumentRoot would be /home/username/public_html/domain1So to get this domain working I just remove that 'domain1' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf domain1
username@hostname [~/public_html]# ln -s ~/addon1_rails/public ~/public_html/domain1
And that's it - browsing to domain1.com will get me my Rails app. This works even if your main domain is already an existing Rails app. - -
For the addon2_static website the process is essentially the same:
In cPanel I would go addon my domain2.com, whose DocumentRoot would be /home/username/public_html/domain2
So to get this domain working I just remove that 'domain2' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf domain2
username@hostname [~/public_html]# ln -s ~/addon2_static ~/public_html/domain2
And that's it - browsing to domain2.com will get me my static website. This, again, also works even if your main domain is already an existing Rails app. - -
For the subdomain_rails website the process is also essentially the same:
In cPanel I would go create my subdomain, whose DocumentRoot would be /home/username/public_html/subdomain
So to get this subdomain working I just remove that 'subdomain' folder cPanel created and make a symlink
username@hostname [~]# cd public_html
username@hostname [~/public_html]# rm -rf subdomain
username@hostname [~/public_html]# ln -s ~/subdomain_rails/public ~/public_html/subdomain
And that's it - browsing to the subdomain will get me my static website. This, again, also works even if your main domain is already an existing Rails app. -----------------------------
Summary
-----------------------------
Essentially - create all your apps and website in folder in your root. Create addon domains and subdomains if you want the DocumentRoot to be different (i.e. if you want them pointing to different folders) - and create a parked domain if you want a domain to point to the same location as another domain. All the magic then happens with the symlink as described above. And you can imagine how helpful this is if you want to setup a test domain and just work the symlinks, or move an app quickly to another domain, etc...
Questions? Corrections? I will update this post as necessary, thanks in advance for your input.
Cheers,
~William