Ruby on Rails
RailsOnMandriva (Version #28)

Here’s a step-by-step guide for making Rails work on Mandriva Linux 2006 and Mandriva 2005LE

Mandriva 2006

We will assume that you have installed a regular Mandriva 2006 with all security fixes applied. This tutorial is suitable to get Rails up and running on Apache2 with MySQL , the default webserver on Mandriva 2006.

Install prerequisites

$ sudo urpmi MySQL-4.1.12-3mdk apache

Install ruby packages.

$ sudo urpmi ruby
$ sudo urpmi ruby-tk ruby-mysql ruby-devel ruby-doc
$ sudo urpmi ruby-RubyGems 

Note: You’re responsible for setting up MySQL yourself.

h3. Install Rails and all its dependencies

Note: answer ‘y’ to all questions

$ sudo gem install rails

Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Updating Gem source index for: <a href="http://gems.rubyforge.org">http://gems.rubyforge.org</a>
Install required dependency rake? [Yn]  y
Install required dependency activesupport? [Yn]  y
Install required dependency activerecord? [Yn]  y
Install required dependency actionpack? [Yn]  y
Install required dependency actionmailer? [Yn]  y
Install required dependency actionwebservice? [Yn]  y
Successfully installed rails-1.0.0
Successfully installed rake-0.7.0
Successfully installed activesupport-1.2.5
Successfully installed activerecord-1.13.2
Successfully installed actionpack-1.11.2
Successfully installed actionmailer-1.1.5
Successfully installed actionwebservice-1.0.0
Installing RDoc documentation for rake-0.7.0...
Installing RDoc documentation for activesupport-1.2.5...
Installing RDoc documentation for activerecord-1.13.2...
Installing RDoc documentation for actionpack-1.11.2...
Installing RDoc documentation for actionmailer-1.1.5...
Installing RDoc documentation for actionwebservice-1.0.0...

Set up development environment. For example, for user sinner we could do:

[sinner@mandriva Documents]$ cd development/ [sinner@mandriva development]$ mkdir ruby [sinner@mandriva development]$ cd ruby/ [sinner@mandriva ruby]$ rails `pwd` exists create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create components create db create doc create lib create lib/tasks create log create public/images create public/javascripts create public/stylesheets create script/performance create script/process create test/fixtures create test/functional create test/mocks/development create test/mocks/test create test/unit create vendor create vendor/plugins create Rakefile create README create app/controllers/application.rb create app/helpers/application_helper.rb create test/test_helper.rb create config/database.yml create config/routes.rb create public/.htaccess create config/boot.rb create config/environment.rb create config/environments/production.rb create config/environments/development.rb create config/environments/test.rb create script/about create script/breakpointer create script/console create script/destroy create script/generate create script/performance/benchmarker create script/performance/profiler create script/process/reaper create script/process/spawner create script/process/spinner create script/runner create script/server create script/plugin create public/dispatch.rb create public/dispatch.cgi create public/dispatch.fcgi create public/404.html create public/500.html create public/index.html create public/favicon.ico create public/robots.txt create public/images/rails.png create public/javascripts/prototype.js create public/javascripts/effects.js create public/javascripts/dragdrop.js create public/javascripts/controls.js create doc/README_FOR_APP create log/server.log create log/production.log create log/development.log create log/test.log [sinner@mandriva ruby]$ ruby script/server => Booting WEBrick... => Rails application started on <a href="http://0.0.0.0">http://0.0.0.0</a>:3000 => Ctrl-C to shutdown server; call with --help for options [2006-01-29 13:34:54] INFO WEBrick 1.3.1 [2006-01-29 13:34:54] INFO ruby 1.8.2 (2004-12-25) [i586-linux-gnu] [2006-01-29 13:34:54] INFO WEBrick::HTTPServer#start: pid=5239 port=3000 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET / HTTP/1.1" 200 7551 - -> / 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /javascripts/prototype.js HTTP/1.1" 200 47603 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /javascripts/prototype.js 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /javascripts/effects.js HTTP/1.1" 200 30257 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /javascripts/effects.js 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /images/rails.png HTTP/1.1" 200 1787 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /images/rails.png 127.0.0.1 - - [29/Jan/2006:13:35:50 EST] "GET /favicon.ico HTTP/1.1" 200 0 - -> /favicon.ico 127.0.0.1 - - [29/Jan/2006:13:38:12 EST] "GET /rails_info/properties HTTP/1.1" 200 917 - -> /rails_info/properties </pre>

Test your Ruby on Rails server:

  1. point your web browser to http://0.0.0.0:3000/
  2. You shold be seeing a webpage saying:

Welcome aboard
You’re riding the Rails!
About your application’s environment

Getting started

Here’s how to get rolling:
1. Create your databases and edit config/database.yml
Rails needs to know your login and password.
2.Use script/generate to create your models and controllers
To see all available options, run it without parameters.
3.Set up a default route and remove or rename this file
Routes are setup in config/routes.rb.

Use with Apache2 on Mandriva

1. Install FastCGI libraries
$sudo urpmi libfcgi0
$sudo urpmi libfcgi0-devel

2. Install FastCGI Apache Module
$sudo urpmi mod_fcgi

3. Install fcgi gem
$gem install fcgi

4. Set proper permissions
$sudo chmod 755 public
$sudo chmod 755 public/dispatch.fcgi
$sudo chmod -R 0666 log
$sudo chmod -R 0666 tmp

5. Add to vhosts.conf
(Replace ‘/var/www/demo/public/’ with path to your project’s public directory and demo.mysite.com with your URL or virtual)

<VirtualHost *>
    ServerName demo.mysite.com
    ServerAlias [<a href="http://www.demo.mysite.com">www.demo.mysite.com</a>]
    DocumentRoot /var/www/demo/public/
    ErrorLog /var/www/demo/log/server.log
    <Directory /var/www/demo/public/>
      Options ExecCGI FollowSymLinks
      AllowOverride all
      Allow from all
      Order allow,deny
    </Directory>
</VirtualHost>

6. Add to beginning of public/dispatch.fcgi
require 'rubygems'
require_gem 'fcgi'

7. Change public/.htaccess from
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

8. Restart httpd server

Mandriva 2005LE

As there are no real ROL packages for Mandriva 2005LE, we will use Mandriva 2006’s packages. After this pre-requsite is completed, proceed to isntall as in Mandriva 2006’s installation process.

Pre-requisite: get MDV2006 packages

  1. Create a local directory on your system to contain your local ruby reposiory. For example, /var/local/ruby
  2. From your friendly Mandriva 2006 mirror, download to that directory all rpm files that start with ruby, from both main and contrib medias. There should be 76 packages using up 19M of disk space.
  3. Generate urpmi metadata for that directory (See “screen capture” below) and check that we do have *.cz files
  4. add a “local ruby” urpmi repository (see “screen capture” below)
  5. install needed ruby packages

“Screen capture”
<pre> [user@mandrake ruby]$ /usr/bin/genhdlist . && /usr/bin/md5sum *.cz > MD5SUM parsing . [user@mandrake ruby]$ ls *.cz hdlist.cz synthesis.hdlist.cz [user@mandrake ruby]$ sudo urpmi.addmedia ruby --nopubkey file://var/local/ruby/ with ./hdlist.cz added medium ruby wrote config file [/etc/urpmi/urpmi.cfg] computing md5sum of existing source hdlist (or synthesis) copying source hdlist (or synthesis) of "ruby"... ...copying done examining hdlist file [/var/cache/urpmi/partial/hdlist.ruby.cz] writing list file for medium "ruby" examining synthesis file [/var/lib/urpmi/synthesis.hdlist.main.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.contrib.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.jpackage.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.updates.cz] performing second pass to compute dependencies

examining hdlist file [/var/lib/urpmi/hdlist.ruby.cz]
built hdlist synthesis file for medium “ruby”
examining hdlist file [/var/lib/urpmi/hdlist.main.cz]
built hdlist synthesis file for medium “main”
examining hdlist file [/var/lib/urpmi/hdlist.contrib.cz]
built hdlist synthesis file for medium “contrib”
examining hdlist file [/var/lib/urpmi/hdlist.jpackage.cz]
built hdlist synthesis file for medium “jpackage”
examining synthesis file [/var/lib/urpmi/synthesis.hdlist.updates.cz]
found 249 headers in cache
removing 0 obsolete headers in cache
wrote config file [/etc/urpmi/urpmi.cfg]
[user@mandrake ruby]$

Install ruby packages.

Proceed just like with Mandriva 2006 (see above)

Install Rails and all its dependencies

Proceed just like with Mandriva 2006 (see above)

Credits

Thanks to LeeO for the FC3 version, as I used it as a template for this entry.

Here’s a step-by-step guide for making Rails work on Mandriva Linux 2006 and Mandriva 2005LE

Mandriva 2006

We will assume that you have installed a regular Mandriva 2006 with all security fixes applied. This tutorial is suitable to get Rails up and running on Apache2 with MySQL , the default webserver on Mandriva 2006.

Install prerequisites

$ sudo urpmi MySQL-4.1.12-3mdk apache

Install ruby packages.

$ sudo urpmi ruby
$ sudo urpmi ruby-tk ruby-mysql ruby-devel ruby-doc
$ sudo urpmi ruby-RubyGems 

Note: You’re responsible for setting up MySQL yourself.

h3. Install Rails and all its dependencies

Note: answer ‘y’ to all questions

$ sudo gem install rails

Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
Updating Gem source index for: <a href="http://gems.rubyforge.org">http://gems.rubyforge.org</a>
Install required dependency rake? [Yn]  y
Install required dependency activesupport? [Yn]  y
Install required dependency activerecord? [Yn]  y
Install required dependency actionpack? [Yn]  y
Install required dependency actionmailer? [Yn]  y
Install required dependency actionwebservice? [Yn]  y
Successfully installed rails-1.0.0
Successfully installed rake-0.7.0
Successfully installed activesupport-1.2.5
Successfully installed activerecord-1.13.2
Successfully installed actionpack-1.11.2
Successfully installed actionmailer-1.1.5
Successfully installed actionwebservice-1.0.0
Installing RDoc documentation for rake-0.7.0...
Installing RDoc documentation for activesupport-1.2.5...
Installing RDoc documentation for activerecord-1.13.2...
Installing RDoc documentation for actionpack-1.11.2...
Installing RDoc documentation for actionmailer-1.1.5...
Installing RDoc documentation for actionwebservice-1.0.0...

Set up development environment. For example, for user sinner we could do:

[sinner@mandriva Documents]$ cd development/ [sinner@mandriva development]$ mkdir ruby [sinner@mandriva development]$ cd ruby/ [sinner@mandriva ruby]$ rails `pwd` exists create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create components create db create doc create lib create lib/tasks create log create public/images create public/javascripts create public/stylesheets create script/performance create script/process create test/fixtures create test/functional create test/mocks/development create test/mocks/test create test/unit create vendor create vendor/plugins create Rakefile create README create app/controllers/application.rb create app/helpers/application_helper.rb create test/test_helper.rb create config/database.yml create config/routes.rb create public/.htaccess create config/boot.rb create config/environment.rb create config/environments/production.rb create config/environments/development.rb create config/environments/test.rb create script/about create script/breakpointer create script/console create script/destroy create script/generate create script/performance/benchmarker create script/performance/profiler create script/process/reaper create script/process/spawner create script/process/spinner create script/runner create script/server create script/plugin create public/dispatch.rb create public/dispatch.cgi create public/dispatch.fcgi create public/404.html create public/500.html create public/index.html create public/favicon.ico create public/robots.txt create public/images/rails.png create public/javascripts/prototype.js create public/javascripts/effects.js create public/javascripts/dragdrop.js create public/javascripts/controls.js create doc/README_FOR_APP create log/server.log create log/production.log create log/development.log create log/test.log [sinner@mandriva ruby]$ ruby script/server => Booting WEBrick... => Rails application started on <a href="http://0.0.0.0">http://0.0.0.0</a>:3000 => Ctrl-C to shutdown server; call with --help for options [2006-01-29 13:34:54] INFO WEBrick 1.3.1 [2006-01-29 13:34:54] INFO ruby 1.8.2 (2004-12-25) [i586-linux-gnu] [2006-01-29 13:34:54] INFO WEBrick::HTTPServer#start: pid=5239 port=3000 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET / HTTP/1.1" 200 7551 - -> / 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /javascripts/prototype.js HTTP/1.1" 200 47603 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /javascripts/prototype.js 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /javascripts/effects.js HTTP/1.1" 200 30257 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /javascripts/effects.js 127.0.0.1 - - [29/Jan/2006:13:35:49 EST] "GET /images/rails.png HTTP/1.1" 200 1787 <a href="http://0.0.0.0">http://0.0.0.0</a>:3000/ -> /images/rails.png 127.0.0.1 - - [29/Jan/2006:13:35:50 EST] "GET /favicon.ico HTTP/1.1" 200 0 - -> /favicon.ico 127.0.0.1 - - [29/Jan/2006:13:38:12 EST] "GET /rails_info/properties HTTP/1.1" 200 917 - -> /rails_info/properties </pre>

Test your Ruby on Rails server:

  1. point your web browser to http://0.0.0.0:3000/
  2. You shold be seeing a webpage saying:

Welcome aboard
You’re riding the Rails!
About your application’s environment

Getting started

Here’s how to get rolling:
1. Create your databases and edit config/database.yml
Rails needs to know your login and password.
2.Use script/generate to create your models and controllers
To see all available options, run it without parameters.
3.Set up a default route and remove or rename this file
Routes are setup in config/routes.rb.

Use with Apache2 on Mandriva

1. Install FastCGI libraries
$sudo urpmi libfcgi0
$sudo urpmi libfcgi0-devel

2. Install FastCGI Apache Module
$sudo urpmi mod_fcgi

3. Install fcgi gem
$gem install fcgi

4. Set proper permissions
$sudo chmod 755 public
$sudo chmod 755 public/dispatch.fcgi
$sudo chmod -R 0666 log
$sudo chmod -R 0666 tmp

5. Add to vhosts.conf
(Replace ‘/var/www/demo/public/’ with path to your project’s public directory and demo.mysite.com with your URL or virtual)

<VirtualHost *>
    ServerName demo.mysite.com
    ServerAlias [<a href="http://www.demo.mysite.com">www.demo.mysite.com</a>]
    DocumentRoot /var/www/demo/public/
    ErrorLog /var/www/demo/log/server.log
    <Directory /var/www/demo/public/>
      Options ExecCGI FollowSymLinks
      AllowOverride all
      Allow from all
      Order allow,deny
    </Directory>
</VirtualHost>

6. Add to beginning of public/dispatch.fcgi
require 'rubygems'
require_gem 'fcgi'

7. Change public/.htaccess from
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

to
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

8. Restart httpd server

Mandriva 2005LE

As there are no real ROL packages for Mandriva 2005LE, we will use Mandriva 2006’s packages. After this pre-requsite is completed, proceed to isntall as in Mandriva 2006’s installation process.

Pre-requisite: get MDV2006 packages

  1. Create a local directory on your system to contain your local ruby reposiory. For example, /var/local/ruby
  2. From your friendly Mandriva 2006 mirror, download to that directory all rpm files that start with ruby, from both main and contrib medias. There should be 76 packages using up 19M of disk space.
  3. Generate urpmi metadata for that directory (See “screen capture” below) and check that we do have *.cz files
  4. add a “local ruby” urpmi repository (see “screen capture” below)
  5. install needed ruby packages

“Screen capture”
<pre> [user@mandrake ruby]$ /usr/bin/genhdlist . && /usr/bin/md5sum *.cz > MD5SUM parsing . [user@mandrake ruby]$ ls *.cz hdlist.cz synthesis.hdlist.cz [user@mandrake ruby]$ sudo urpmi.addmedia ruby --nopubkey file://var/local/ruby/ with ./hdlist.cz added medium ruby wrote config file [/etc/urpmi/urpmi.cfg] computing md5sum of existing source hdlist (or synthesis) copying source hdlist (or synthesis) of "ruby"... ...copying done examining hdlist file [/var/cache/urpmi/partial/hdlist.ruby.cz] writing list file for medium "ruby" examining synthesis file [/var/lib/urpmi/synthesis.hdlist.main.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.contrib.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.jpackage.cz] examining synthesis file [/var/lib/urpmi/synthesis.hdlist.updates.cz] performing second pass to compute dependencies

examining hdlist file [/var/lib/urpmi/hdlist.ruby.cz]
built hdlist synthesis file for medium “ruby”
examining hdlist file [/var/lib/urpmi/hdlist.main.cz]
built hdlist synthesis file for medium “main”
examining hdlist file [/var/lib/urpmi/hdlist.contrib.cz]
built hdlist synthesis file for medium “contrib”
examining hdlist file [/var/lib/urpmi/hdlist.jpackage.cz]
built hdlist synthesis file for medium “jpackage”
examining synthesis file [/var/lib/urpmi/synthesis.hdlist.updates.cz]
found 249 headers in cache
removing 0 obsolete headers in cache
wrote config file [/etc/urpmi/urpmi.cfg]
[user@mandrake ruby]$

Install ruby packages.

Proceed just like with Mandriva 2006 (see above)

Install Rails and all its dependencies

Proceed just like with Mandriva 2006 (see above)

Credits

Thanks to LeeO for the FC3 version, as I used it as a template for this entry.