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:
1 2 3 4 5 6 7 |
DocumentRoot /var/www/railstest/public ServerName railstest.cosninix.com RailsBaseURI / RailsEnv development <Directory "/var/www/railstest/public"> allow from all Options -MultiViews |
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"
1 2 3 4 5 6 7 8 9 10 11 |
<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> |
1 |
require 'rubygems' |
1 |
require 'sinatra' |
1 |
set :environment, :production |
1 |
disable :run, :reload |
1 |
require 'testje' |
1 |
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)
1 |
get '/' do |
1 |
"hello world, my name is Frank" |
1 |
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
1 |
touch tmp/restart.txt |
every time you changed something. This will trigger passenger to reload everything