theKindOfMe

October 24, 2010

Rails 3 on Ubuntu 10.10 with RVM, Passenger and Nginx

Filed under: Uncategorized — Tags: , , — yasi8h @ 1:09 am

This covers setting up a Ubuntu 10.10 box to run rails 3 on production. Please notice it only focus on installing and setting up things mentioned in the title. However there are other things that you should configure and setup when deploying a application to production (like ntpd for example).

Installing RVM

We will need git before we can get started.

sudo apt-get install git

Install rvm according to the official guide.

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

add

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

to your .bashrc.

Once you edit your bashrc file execute the following to load rvm without logging out and back in

source ~/.rvm/scripts/rvm

Just to be safe check wether rvm is a function, which is what it should be.

type rvm | head -n1

Install ruby 1.9.2

See what you get out of rvm notes. you will need to install some stuff before you can compile ruby.

aptitude install build-essential bison openssl libreadline5 libreadline5-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libmysqlclient-dev

The above packages covers some common stuff. It should be enough to get you started. However depending on what gems you want to install you might need to install additional dependencies.

rvm install 1.9.2

Set 1.9.2 as the default

rvm use 1.9.2 --default

Passenger

Install passenger as instructed in rvm documentation http://rvm.beginrescueend.com/integration/passenger/

rvm 1.9.2 --passenger
rvm 1.9.2
gem install passenger
rvmsudo passenger-install-nginx-module

Let passenger downland and install nginx for you.

Modify /opt/nginx/conf/nginx.conf (thats the default location).

‘For Nginx users, replace the passenger_ruby line with:’

passenger_ruby /home/wayne/.rvm/bin/passenger_ruby;

Add a block like this to host your RoR site

server {
      listen 80; #the server will be running on this port
      server_name www.yourhost.com;
      root /home/deployer/your_rails_project/public;   # <--- be sure to point to 'public'!
      passenger_enabled on;
   }

Nginx init script

From: http://github.com/jnstq/rails-nginx-passenger-ubuntu

cd
git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
sudo chown root:root /etc/init.d/nginx

More information on http://wiki.nginx.org/Nginx-init-ubuntu

MySQL

sudo apt-get install mysql-client mysql-server

Get the source for your rails app. unzip it in your home folder (or where ever you want to. But be sure to edit the nginx config as appropriate).

cd to-your-rails-app-folder
bundle install
rake db:setup RAILS_ENV=production

sudo /etc/init.d/nginx restart

Thats it!

About these ads

21 Comments »

  1. the following command did not work for me:
    source ~/.rvm/scripts/rvm

    instead:
    source ~/.rvm/src/rvm/scripts/rvm

    so if you get any message that it cannot find the rvm script or that it thinks rvm is a directory, please traverse the path and find out exactly where curl places the script files.

    Comment by vish — November 11, 2010 @ 12:09 am

    • RVM must have changed its directory structure. Yep thats the case.

      Comment by yasi8h — November 11, 2010 @ 3:15 pm

  2. I would do this first:

    – this is closer to what you would do after you have installed Ubuntu and contains CURL which you need to install RVM.

    aptitude install build-essential bison openssl libreadline5 libreadline5-dev curl git-core zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libmysqlclient-dev

    Comment by vish — November 11, 2010 @ 12:14 am

  3. Thanks for this guide. It was very useful.

    Comment by morr — November 29, 2010 @ 4:22 am

  4. When I run
    rvm 1.9.2 –passenger
    I get
    If you are using Passenger 3 you no longer need the passenger_ruby,
    use the wrapper script for your ruby instead (see ‘rvm wrapper’)

    Comment by makka — December 28, 2010 @ 8:57 pm

  5. I have the same problem as makka.

    Comment by Manwell — January 18, 2011 @ 7:34 am

  6. I think you should add autoconf to the aptitude install list

    Comment by Andreas Franzén — February 22, 2011 @ 4:11 pm

  7. Great One!
    thanks man >>from Egypt :)

    Comment by Muhammad Negm — March 1, 2011 @ 11:48 pm

  8. [[ -s “$HOME/.rvm/scripts/rvm” ]] && . “$HOME/.rvm/scripts/rvm” # This loads RVM into a shell session.

    Shouldn’t this line point to the install at /usr ?

    Comment by Joseph — April 3, 2011 @ 1:48 am

    • It would depend on where rvm is installed.

      Comment by yasi8h — April 3, 2011 @ 2:59 am

  9. I might be missing something, but wouldn’t you have to install Rails at some point?

    Comment by joshua — May 6, 2011 @ 3:49 am

    • It’s my fault that i didn’t include it. Just do a gem install rails after everything is done.

      Comment by yasi8h — May 6, 2011 @ 4:02 am

  10. Thanks! :)

    Now I am fighting a 403 error with nginx. Any ideas?

    Comment by joshua — May 6, 2011 @ 4:20 am

  11. small adds… if you installing environment on clean machine..
    before installing rvm:
    $ apt-get -y install aptitude curl autoconf ;)

    Comment by sfate — May 15, 2011 @ 4:11 pm

    • thanks for the input!

      Comment by yasi8h — May 16, 2011 @ 1:08 am

  12. So, do you in general install this as root user or did you create another user to install this for him?

    If you install it as root rvm gets installed in /usr/lib, where other users will have problems to install gems into/from except using sudo, am I right or am I missing something?

    Comment by Ben — May 21, 2011 @ 10:34 am

    • I generally install RVM under the ‘deploy’ user (just a normal user created for deployment related tasks). What you said about installing rvm as root is correct. You can more information about this from here.

      Comment by yasi8h — May 21, 2011 @ 3:22 pm

  13. when I use ‘gem install passenger’

    and I got the below error msg:

    xzy@xzy-computer:~$ gem install passenger
    ERROR: Loading command: install (LoadError)
    no such file to load — zlib
    ERROR: While executing gem … (NameError)
    uninitialized constant Gem::Commands::InstallCommand

    so,how can I solve it?thanks

    Comment by xiangzhuyuan — June 1, 2011 @ 5:46 am

  14. Thanks, your guide helps me a lot.

    Comment by MF — June 20, 2011 @ 5:59 am

  15. thanks yow

    Comment by JaWaica (@Jawaica) — June 26, 2012 @ 5:44 am


RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: