Tuesday, April 5, 2011

Install Ruby 1.9.3 + Rails + Passenger + Node.js On Centos 6.3 x64

This is presuming a vanilla, bare bones install of CentOS with Apache 2.x installed

First we need to prep the system with some required tools
yum groupinstall "Development Tools"
yum install curl-devel openssl-devel httpd-devel apr-devel apr-util-devel libzlib-ruby zlib-devel

We need libyaml
cd /usr/local/src
wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzvf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local && make && make install

We need Node.js (preferred JavaScript run-time)
cd /usr/local/src
wget http://nodejs.org/dist/v0.8.19/node-v0.8.19.tar.gz
tar zxvf node-v0.8.19.tar.gz
cd node-v0.8.19
./configure && make && make install

We need Ruby
cd /usr/local/src
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p385.tar.gz
tar -zxvf ruby-1.9.3-p385.tar.gz
cd ruby-1.9.3-p385 
./configure && make && make install

Now we just have to install Passenger
/usr/local/bin/gem update --system
/usr/local/bin/gem install passenger
/usr/local/bin/passenger-install-apache2-module

Presuming that bit went according to plan put the following into:

/etc/httpd/conf.d/passenger.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.6/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.6
PassengerRuby /usr/local/bin/ruby

Now install rails
/usr/local/bin/gem install rails

Next we edit the Apache config
nano /etc/httpd/conf/httpd.conf
...add "ExecCGI" to the "Options" line of your DocumentRoot and under "AddHandler cgi-script" add ".rb"

Now just restart Apache
service httpd restart

Lastly, lets test by creating a "hello world" example in:
/var/www/html/index.rb

...with this content (chmodd'd to 755)
#!/usr/local/bin/ruby -w
print "Content-type: text/html\n\n"
print "Hello World!\n"

Now view the servers' IP in your browser and if it comes up without issue then you are good to go working ruby as CGI.

But we want to use rails, so our next step is to create a rails application:
cd /var/www/html
rails new testApp
cd testApp
bundle install
bundle update
rake db:create
rails server
Now view the servers' IP in a browser followed by port 3000 and if you see the ruby welcome screen you're good to go working with Ruby On Rails.