For me personally, the main thing that delayed me getting into rails or django development, was the webserver setup.
Let me explain a bit on how to configure your Apache VirtualHost directives so you can host your apps on subdomains on the fly without having to change your DNS or serversetup.
In the end’ll we’ll have apps running on subdomains such as http://myapp.rails.mydomain.com
Initial software requirements
For now i’m leaving the installation of server software like ruby, fastcgi etc.. as it is, its covered on the ruby on rails site pretty clearly.
Setting up Apache for Rails
The trick is letting your Apache virtual host listen to hostnames with a wildcard in ServerAlias and in VirtualDocumentRoot and allowing your DNS to resolve wildcard subdomains.
UseCanonicalName Off
ServerAlias *.rails.mydomain.com
VirtualDocumentRoot /var/www/mydomain.com/subdomains/rails/%1/public/
ErrorLog logs/rails.mydomain.com-error_log
CustomLog logs/rails.mydomain.com-access_log common
Options FollowSymLinks Indexes
AllowOverride All
This VirtualHost directive will now accept Host names such as http://blabla.rails.mydomain.com and http://slippery.rails.mydomain.com
Lower in the VirtualHost we define a VirtualDocumentRoot which matches the first part of our subdomain to a folder on the filesystem. This VirtualDocumentRoot whill match paths such as /var/www/mydomain.com/subdomains/rails/blabla/public and /var/www/mydomain.com/subdomains/rails/slippery/public
Now we place our Rails app in /var/www/mydomain.com/subdomains/rails/slippery and it’ll be accessible via http://slippery.rails.mydomain.com. If you try that now you’ll get an error, hang on we’re not there yet.
In the .htaccess file Rails generates in the public folder we need to change the line that says
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
to
RewriteRule ^(.*)$ /dispatch.fcgi [QSA,L]
for some reason that does the trick, i’m not sure why but I’m thinking it’s got something todo with the path & url rewriting magic that Apache is doing behind the scenes to match the VirtualDocumentRoot. If anyone got the exact reason or how to bypass this step please let me know : )
DNS Setup
Make sure you have a wildcard record setup for your DNS. You need to add an A record that resolves *.rails.mydomain.com to the IP address of your webserver. This will allow DNS requests to http://slippery.rails.mydomain.com to resolve magically to your webserver and will allow you to instantly see you new apps you’ve placed on your server without having to update your DNS and then wait for your DNS to refresh.
Test your setup!
Go to http://slippery.rails.mydomain.com and your app should greet you with a smile. From now on if you’ve got a new app place it in the /var/www/mydomain.com/rails/ folder and it’ll be instantly accessible from via *.rails.mydomain.com
Make sure you’ve got your database settings correctly and your app should be running.
I’ve got this setup for django aswell and will post it soon.
Leave some feedback and/or corrections in the comments, thanks.




