I would like to thank Adam Miller very much for working with me to create an environment that can run ruby on rails, and for providing this great how-to for creating rails application on cias.rit.edu I personally cannot take any responsibility for the great work he’s done documenting these steps. Bravo Adam.
You should be comfortable typing in commands to a command line interface. You should also be sure to have rails, mysql, and a server running on your local machine for development. Your rails app will run in production mode on the CIAS server, so you will not be able to access many of the debugging tools that development mode offers you.
That sound good? Alright, here we go!
Step 1: Creating the Apps Directory
For reasons of security and flexibillity, I’m going to recommend creating a directory for your applications to live in. We don’t want to have your apps live in a public facing directory so lets create it as low as we can go (your home folder).
Step 2: Setting up your app
We’re already to go now just call the rails command to build your new application:
This will create a brand new rails app for you. If you already have been developing your application locally, you can also deploy your application here. Hopefully your using subversion to manage your files and you can just checkout a version of your app:
[code]svn co path-to-repository app-name[/code]
If not you could use ftp to get your local files up on the server, although I would not recommend this method at all.
Step 3: Set permissions
By default, the permissions will be set incorrectly, and we can’t have that.
chmod 755 *[/code]
I’ve also found that if your generating a new rails app, your tmp directory and its contents will have incorrect permissions as well.
[code]chmod 777 tmp/* tmp[/code]
Step 4: Create the symbolic link
Create a symbolic link to your apps public directory. For this tutorial, I’m assuming you will want to run your application from the apps directory we set up in step 1.
[code]ln -s ~/apps/your-apps-dir/public/ ~/public_html/app-shortcut-name[/code]
If you want your application to run at your root level, then replace your public_html folder with your symbolic link.
[code]mv ~/public_html ~/public_html_backup
ln -s ~/apps/your-apps-dir/public/ ~/public_html/
Step 5: Edit your .htaccess file.
In your apps public directory, edit the .htaccess file using your favorite editor. Because your app is not going to be running at the root level (if it is, you may be able to just skip this step), you’ll need to tell the server how it should map your urls. Above the very first RewriteRule add this line.
Again, if your running your app in your public root, just leave off the symbolic-link-name.
We also need to make sure apache knows we want to use fastcgi to run our application. Add this line to the top of your .htaccess file:
AddHandler fcgid-script .fcgi
Then we also need to rewrite this line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
[code]RewriteRule ^(.*)$ dispatch.fcgi [QSA,L][/code]
So that we make sure we’re using fastcgi insead of just cgi. Your app will be painfully slow (and consume a lot of resources) if your not running with fastcgi.
Now you should be able to visit
And you should see the rails welcome message. If your deploying an application that you have already started, you may see an error instead of the rails welcome message. Don’t worry about this as we have not finished setting up the database yet. Onward ho!
Step 6: Database hookups
You’ll need to edit the production database values in database.yml. Each cias account (as far as I know) comes with a mysql database in the name of your account. So we can edit it to look something like this:
Step 7: Production mode
As of this writing, cias.rit.edu is not set up to force your app into production mode by default. It’s important to run production mode because it is more secure and consumes less resources. In the app of your rails directory, open up config/enviornment.rb and add this line somewhere towards the top:
[code]ENV[‘RAILS_ENV’] ||= ‘production'[/code]
Step 8: Enjoy!
And that should do it! Your app should be up and running. If you have problems feel free to shoot me an email: acm6603[at]gmail.com. Google is also very helpful even though it won’t be specific to this server.