getting ruby, rails, passenger on my centos box

Do not yum for ruby, cause you’ll get 1.8.5.
Follow these steps to get everything installed: http://www.catapult-creative.com/2009/02/04/installing-rails-on-centos-5/

Then create a passenger virtualhost:

<VirtualHost *:80>
 DocumentRoot /var/www/railstest/public
 ServerName railstest.cosninix.com
 RailsBaseURI    /
 RailsEnv development
 <Directory "/var/www/railstest/public">
 allow from all
 Options -MultiViews
 </Directory>
</VirtualHost>

Watch:  railsEnv is mandatory!  This is not in the passenger doc but gives you a 500-internal server error if missing.

Now go to /var/www and create your rails app (and use mysql as well)

rails new railstest -d mysql

restart httpd and we should see the generated index.html, but that is still static html processed so no rails nor ruby is actually used.

Now remove index.html from railstest/public and generate a test controller:

rails generate controller home index

And change the default route (config/routes.rb) for the root: (search for root, it is already there but commented out)

Blog::Application.routes.draw do
root :to => "home#index"
now restart httpd and you should see rails at work.
Then it might be nice to have a sinatra setup as well.
Create another virtual server, this time it is called sinatratest:
<VirtualHost *:80>
 DocumentRoot /var/www/sinatratest/public
 ServerName sinatratest.cosninix.com

 RackEnv production

 <Directory "/var/www/sinatratest/public">
 allow from all
 Options -MultiViews
 </Directory>
</VirtualHost>
Also here, the RackEnv is mandatory!
Now create the sinatratest dir and a public dir.
Leave the public dir empty, it is a placeholder for now but can be filled with javascript files and css etc.
Create a file called config.ru in the sinatratest dir (this is a rack definition file that passenger accepts)
require 'rubygems'
require 'sinatra'
set :environment, :production
disable :run, :reload
require 'testje'
run Sinatra::Application

This is for the latest sinatra version (1.2.0) as some methods has changed names and/or became class methods.

now create a small file testje.rbin (also in the sinatratest dir)

get '/' do
   "hello world, my name is Frank"
end

Restart httpd and this should work. You now have a working rails and sinatra deployment on centos with passenger.

One tip: Instead of restarting httpd all the time it is easier to create a tmp dir and use

touch tmp/restart.txt

every time you changed something. This will trigger passenger to reload everything

7 Responses to “getting ruby, rails, passenger on my centos box”

  1. Mr Ezy 2 April 2011 at 21:31 #

    Great post!

  2. tabletki odchudzajace 10 April 2011 at 00:38 #

    You post informative articles Just bookmarked !!!

  3. Cammy Nathoo 19 April 2011 at 10:49 #

    restart httpd and we should see the generated index.html, but that is still static html processed so no rails nor ruby is actually used.
    +1

  4. Rubin Wiltgen 17 June 2011 at 18:46 #

    Hi there, just became aware of your blog through Google, and found that it is truly informative. I am going to watch out for brussels. I will appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

  5. Armandina Salamon 13 March 2012 at 05:17 #

    Great article indeed. We possess been awfully scouting around to the good tips.

  6. Brendon Sheffey 20 March 2012 at 10:52 #

    This is the perfect site for anybody who would like to find out about this topic. You realize a whole lot its almost tough to argue with you (not that I personally would want to…HaHa). You certainly put a fresh spin on a subject that’s been discussed for many years. Excellent stuff, just wonderful!

  7. loodgieter tilburg 29 March 2012 at 08:42 #

    Greetings! Very helpful advice in this particular article! It is the little changes that produce the largest changes. Many thanks for sharing!

Leave a Reply