Ruby on Rails
HowtoInstallOnTextDrive

This is a simple method to get multiple rails sites up and running for a default TextDrive setup.

With more advanced setups the rewriting rules may not work (e.g. if you don’t have mod_vd), in which case the alternative is to add a new virtual host container (submit a support request if you don’t know how).


Assuming sites_directory == /usr/home/_your_username_/sites

Q:What if there is no sites/ directory? What if all you have are
Maildir/, etc/, logs/, public_html/, cgi-bin/, home/, php-fastcgi/, and svn/ ?

A:Rails will make it for you. You can also mkdir and make one.

mkdir sites or
mkdir ~/sites

To create a rails app, do the following:

1. run the command “rails _sites_directory_/_app_name_”

2. run the command “ln -s ../_sites_directory_/_app_name_/public /usr/home/_your_username_/public_html/_app_name_”. This will create a symbolic link to your application in your public_html directory.

3. ensure the following is in your .htaccess file (in public_html)

AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

RewriteEngine On

(Newer versions of Rails already include these lines)

For subdomains on the newer boxes, the .htaccess file is located in: /users/home/username/domains/yourdomain/sites/your-rails-app/public

Don’t forget it’s an invisible file so you have to do “ls -a” to see it.

4. add the following lines to the same .htaccess file (i.e. once for each app).

If you have html files that should not be handled by rails, use this:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi?$1 [QSA,L]

to make sure that local files are displayed.

To redirect everything to rails just use this:


RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]

NB: By default TextDrive is set up to magically allow sub.your_hostname.com to point to your_hostname.com/sub which causes problems with routes and rewrites. You can either use a virtual host as explained by octopod, or you can remove the *.your_hostname.com entry in Webmin > Apache Webserver > virtual server for your_hostname.com > Networking and Addresses. Remember to apply changes.

Further specialized rewriting rules, can now be specified by using routes which makes it possible to e.g. go directly to a specific controller when accessing app_name.your_hostname.com.
To do this, you need to edit _sites_directory_/_app_name_/config/routes.rb. find


map.connect ‘:controller/:action/:id’

and add the name (and action) of your controller like this:


map.connect ‘:controller/:action/:id’, :controller => ‘_your_default_controller’, :action => ‘_your_action’

The action defaults to ‘index’, so if you don’t want to call ‘new’ or something like that, just leave out the action-part.

5. setup your database and rails config file. You are in a shared environment so you need to put your mysql user and password in the database.yml file

production:
   adapter: mysql
   database: {YOUR TEXTDRIVE MYSQL DATABASE}
   host: localhost
   username: {YOUR TEXTDRIVE MYSQL USER}
   password: {YOUR TEXTDRIVE MYSQL PASSWORD}

if you have your Rails environment set to “development” (the default), instead of “production” you need to change it.

Add the follow line just after the shebang (the first line) in config/environment.rb:

ENV['RAILS_ENV'] = "production"

6. code away!


From “this ”http://wiki.rubyonrails.com/rails/pages/TextDrive" class="existingWikiWord">TextDrive thread":http://textdrive.com/forum/viewtopic.php?id=782.

As you may read on the above link, it might be good to submit a ticket for a virtual host on your Rails directory, or else the rewrite rules may act funny or don’t work at all – Nicolas Mommaerts

7. Getting 500 errors in your logs?

The ones I’ve seen most frequently on TxD:

  1. Note that “env” isn’t available in production, so “/usr/bin/env ruby” should be replaced with: “/usr/local/bin/ruby”

8. Getting 403 (forbidden) errors in your logs?
Go back to step 3, your .htaccess probably isn’t right.

9. Where to put Rails apps if you have more than one

Following Kyle’s example, I put them in ~~/railsapps (or in railsapps for that virtual host) — that way if I’ve got more than one, they’re all in the same place. Easier for the admins if they need to see what’s going on.

Then you need to symlink the public directory of the rails app to the place in the document tree:

ln -s ~~/railsapps/myapp/public/ ~/web/public/myapp/

(I’m on Davie, so that’s my directory structure)

See also FastCGI on unix linux bsd

category:Howto
[Note: cs327: I’m not the original writer of this howto, I merely rolled it back to its proper form as some idiot had inserted some junk]