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 http://us.archive.ubuntu.com/ubuntu/ karmic main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic main restricted

deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates main restricted
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates main restricted

deb http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic universe
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates universe

deb http://us.archive.ubuntu.com/ubuntu/ karmic multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic multiverse
deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse

deb http://security.ubuntu.com/ubuntu karmic-security main restricted
deb-src http://security.ubuntu.com/ubuntu karmic-security main restricted
deb http://security.ubuntu.com/ubuntu karmic-security universe
deb-src http://security.ubuntu.com/ubuntu karmic-security universe
deb http://security.ubuntu.com/ubuntu karmic-security multiverse
deb-src http://security.ubuntu.com/ubuntu 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
wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
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
passenger-install-nginx-module

Create the script for starting and stopping nginx server:

sudo nano /etc/init.d/nginx

Copy this to the new file. 

#! /bin/sh

### BEGIN INIT INFO
# 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
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

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

set -e

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

    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.