This is one of my "Getting Things Right" posts, a.k.a, "How The Hell Do I Set Up My Rails Site on a VPS host." It's almost always more difficult to get things right than get things done. I tried Slicehost and Linode before and I always ended up rebuilding because I couldn't get the right setup.

Rails 3 is a little more painful than 2.3.5. This is not due to the framework itself but due to deployment issues. This dissuades a lot of people from even trying. Why should you bother using something that doesn't work on any of your servers? But which is important? "Your application" or "your server" ? Remember that you server exists for your application and not otherwise.

I thought about the idea today as i's Easter Sunday. Happy Easter, all. It’s time to kill the stuff that "kills your time," and wake up from a really bad dream full of passenger errors.

So little time, so much to do. Why should I bother thinking too much. As someone told me, it's not worth pulling your hair for — go get a VPS.

32-bit or 64-bit?

I always choose 32-bit regardless of the plan I take. I took a plan with 768MB memory and still chose 32-bit because based on experience, 768MB is never enough for some applications to run.

So here's the lengthy guide on setting up Rails 3 on Ubuntu Karmic Koala. I may add in comments and stuff I missed later but this should work for you as it worked for me.

When using root, you may not use sudo anymore.

Edit sources list:

nano /etc/apt/sources.list

It should have: 

deb karmic main restricted
deb-src karmic main restricted

deb karmic-updates main restricted
deb-src karmic-updates main restricted

deb karmic universe
deb-src karmic universe
deb karmic-updates universe
deb-src karmic-updates universe

deb karmic multiverse
deb-src karmic multiverse
deb karmic-updates multiverse
deb-src karmic-updates multiverse

deb karmic-security main restricted
deb-src karmic-security main restricted
deb karmic-security universe
deb-src karmic-security universe
deb karmic-security multiverse
deb-src karmic-security multiverse

Update Ubuntu.

sudo apt-get update
sudo apt-get dist-upgrade

Set up locale:

sudo locale-gen en_US.UTF-8
sudo /usr/sbin/update-locale LANG=en_US.UTF-8

Install build-essential:

sudo apt-get install build-essential

Install Ruby 1.8.7

sudo apt-get install ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby libncurses-ruby 
libcurses-ruby libruby libruby-extras libfcgi-ruby1.8 build-essential libopenssl-ruby libdbm-ruby libdbi-ruby
 libdbd-sqlite3-ruby sqlite3 libsqlite3-dev libsqlite3-ruby libxml-ruby libxml2-dev ri1.8 rdoc1.8

As of this date, there are still some issues with Rails 3 and Ruby 1.9.1. There is a segmentation fault when running “rails server”. It neither works on development or production for me. Until it does work, I will use 1.8.7.

Install rubygems version 1.3.6. Rails 3 Beta 2 requires 1.3.6.

mkdir src
cd src
sudo apt-get install wget
tar xvzf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ruby setup.rb

Install the mysql gem (for those using mysql). Since it’s VPS, why not use PostgreSQL? Go ahead and google that if that’s what you need.

sudo apt-get install libmysqlclient-dev
sudo gem install mysql --no-rdoc --no-ri

Install Phusion Passenger requirements and the passenger gem.

sudo apt-get install libc6 libpcre3 libpcre3-dev libpcrecpp0 libssl0.9.8 libssl-dev zlib1g zlib1g-dev lsb-base

sudo gem install passenger

Create the script for starting and stopping nginx server:

sudo nano /etc/init.d/nginx

Copy this to the new file. 

#! /bin/sh

# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon


test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx

set -e

case "$1" in
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$ \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$ \
                --exec $DAEMON
        echo "$NAME."
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$ --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$ --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$ \
              --exec $DAEMON 
          echo "$NAME."
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1   

    exit 0

Edit permissions of the script.

sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

sudo /etc/init.d/nginx start

And finally install Rails 3 Beta 2

sudo gem install arel tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler 
sudo gem install rails --prerelease

Other things you should never forget:

Postfix for sending email

sudo apt-get install postfix

Git for source control management

sudo apt-get install git-core
comments powered byDisqus

Hello! I am Kat. I've been a developer for several years. When I'm not sitting down, reading and working for long hours, I am traveling to some place of interest.
If you want to reach out, you can send me an email or add me up on Google Plus.