Rails Production Deployment With Site5 (Screencast)

Warning:
There is an error in this screencast when I'm copying over my application. In the video I say "yourrailsapp/vendor/public/*" when really this should read "yourrailsapp/public/*". Even with this fix, I think the folders & files I choose to copy over were application specific - and you'll need to consider this when deploying your own application.

Deploying your first Rails application can be an intimidating process if your new to SSH or Passenger. For this reason, I've put together a Screencast that walks through steps required to launch a basic application. This being said, there are a few extra steps involved when getting an application running properly.

You first need to make sure that you have your gems configured properly; I would recommend following this handy tutorial over at the Site5 forum which explains how to setup and install your own gems. Also, the steps below are meant to work with the Screencast and are not a complete explanation of everything required to get your app running.

Feel free to leave any (productive) comments below. I'm sure that I've missed some important aspects of deployment, but for me this seemed to do the trick! Thanks for checking out my site and good-luck with your app!

# Step 1.
# Create Rails App (with MySQL)
rails appname -d mysql

# Step 2.
# Delete existing public_html directory

# Step 3.
# Make sure permissions are setup properly
chmod -R 755 /home/app/*

# Step 4.
# Create a symbolic link from the public directory of 
# your rails application to public_html
ln -s /home/username/app/public public_html

# Step 5.
# Verify that the symbloic link worked by visiting your domain

# Step 6.
# Remove the default rails index
rm /home/username/app/public/index.html

# Step 7.
# Create and setup the .htaccess
# Use nano, pico, or vi to create this file
RailsEnv production
PassengerEnabled on
PassengerAppRoot /home/username/app

# Step 8.
# Copy over your application
# This depends on your app, but should generally
# include: apps, config, migrations, plugins

# Step 9.
# Setup your environment.rb file
# I'm using my own gems, which is why I declare my custom 
# gem_path
ENV['GEM_PATH'] = '/home/username/gems:/usr/lib/ruby/gems/1.8'
RAILS_ROOT = '/home/username/app/'
ENV['RAILS_ENV'] = "production"
RAILS_ENV  = ENV['RAILS_ENV']

# Step 10.
# Create the restart file. This is done using
# Nano, vi, or pico. Passenger uses this to restart your app.
nano app/tmp/restart.txt

# Step 11.
# Freeze your rails installation.
rake rails:freeze:gems

# Step 12.
# Freeze any gems your application requires.
rake gems:unpack:dependencies

# Step 13.
# Setup your databases. Create your MySQL databases using the
# Site5 'site admin.' You'll need to alter your
# app/config/database.yml file.


# Step 14.
# Rake the database
rake db:migrate

# Step 15.
# Make the next Twitter!
  1. 415f52f9b69778bb421b48871f25da1c

    Dan

    2:24 AM on Sunday, April 11th, 2010

    I followed these steps, four times actually, just to make sure I had done it correctly. I couldn't get the site to load properly. I ran into a lot of errors that weren't covered here.

    Your steps are mis-numbered (you have two step sixes and sevens).

    Sometimes site5's shell will kill the command (such as rake gems:install) so people should be aware of that and re-run it when it's killed.

    After step 6 (second one)
    I refreshed the page and got:
    "We're sorry, but something went wrong."
    instead of the Passenger error complaining about the gems.

    I'll post the rest of my feedback in the next two comments.

  2. 4a24c05eeb9e3ae07ac3a63b5fafa9da

    Emerson

    7:06 AM on Sunday, April 11th, 2010

    Thanks for the input Dan. I'll go through this tomorrow and see if I missed anything. For the record, this is really a screencast and the instructions I give above are supposed to be used within that context. I've also made some assumptions about people having custom gems setup, but I should probably mention that somewhere.

    Regardless, if you've watched the screencast, my app seems to work fine at the end. With so much diversity in Rails applications it's hard to write a definitive guide to deployment.

  3. 3a5f2abdf796569c6190aa6e1532cc02

    Sean Rankin

    6:43 AM on Friday, May 14th, 2010

    I'm a designer by trade and a hack of a programmer... I've only been messing with Rails for 2 weeks and I was worried that I wouldn't be able to figure out deployment with Site5. After a couple hours + your screencast, I've got a respectable app up and running. Thanks man. Great work!

  4. Cdbcf0af918dce6b05be72aeca705633

    Mike

    5:14 AM on Wednesday, September 29th, 2010

    The issue relating to running the rake command for gems is that it consumes a lot of memory and will not complete on a shared host where allocations are limited. Do the gem unpacking before you upload your application. This will save you a lot of time and actually makes sense since you want to SHIP your project with no dependencies.

  5. A310b2c20365cfb3625400b372eb671c

    Aslam Najeebdeen

    6:08 AM on Friday, October 1st, 2010

    Excellent Emersion!

    I'm a sort of visionary person who always search screencasts first for any sort of learning. This is exactly what I expected. You made my day!

    Thanks a bunch!

    Best,
    Aslam

  6. 4a24c05eeb9e3ae07ac3a63b5fafa9da

    Emerson Lackey

    5:27 AM on Saturday, October 2nd, 2010

    @Aslam,

    Thanks for the message. really nice to hear that some people are enjoying and using the screencasts I've put together.

  7. 4a24c05eeb9e3ae07ac3a63b5fafa9da

    Emerson Lackey

    5:31 AM on Monday, November 22nd, 2010

    I'm going to update this soon with information about getting Rails 3 up and running (which this blog is now using). Feels really good to have an up-to-date framework.