Ruby on Rails
HowtoInstallOnGentooWithApache

If it’s not obvious from the Rails versions referred to, this is very, very out of date. Hopefully we will eventually get around to updating this. – Josh Nichols (aka nichoj, technicalpickles), Gentoo/Ruby maintainer

Rails-0.11.0-r1 and newer

As of rails-0.11.0-r1 on Gentoo, all you need to do is:

echo "dev-ruby/rails mysql fastcgi" >> /etc/portage/package.use
emerge -av rails
(type in 'y' if everything looks correct)
rails /path/to/app
</pre>

You could add different databases to your USE: sqlite, postgres etc.

We’ve also added a patch to dispatch.fcgi and a patch to ruby-fastcgi, so as of 0.11.0, using the ebuilds is a good way to get patched easily.


Rails-0.10 and older

Install Ruby and RubyGems

su -
emerge -av ruby rubygems

To test your Ruby install

ruby -v

Install Rails and FastCGI?

emerge -av dev-ruby/rails

Configure Apache

Add:

-D FASTCGI

to APACHE2_OPTS in /etc/conf.d/apache2

The following line in /etc/apache2/conf/apache2.conf must be uncommented (that is, if you find it commented)

Include conf/vhosts/vhosts.conf

Add the following lines to /etc/apache2/conf/vhosts/vhosts.conf :

Listen 127.0.0.1:8000
<VirtualHost 127.0.0.1:8000>
  ServerName some_name
  DocumentRoot /path/to/your_application/public/
  ErrorLog /path/to/your_application/log/apache.log

  <Directory /path/to/your_application/public>
    Options ExecCGI FollowSymLinks
    AddHandler cgi-script .cgi
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

With apache-2.0.55 and higher, the new location for default virtual host is /etc/apache2/vhosts.d/00_default_vhost.conf

Set up Rails application

cd /www_root/
mkdir rails_app
cd rails_app
rails .

Edit /rails_app/public/.htaccess and change:

RewriteRule ^(.*)$ dispatch.cgi?$1 [QSA,L]

to

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

Note that if you are using FCGID instead of FastCGI, you will also have to change

 AddHandler fastcgi-script .fcgi

to

 AddHandler fcgid-script .fcgi

Browse to _http://127.0.0.1:8000 _ and you should see the Rails welcome screen.

-

What about the FastCgiIpcDir? /tmp/fcgi_ipc/ that is setup on the other distros? Is that still necessary in gentoo’s configurations?

Personally, I didn’t have to set up that directory (on the file-system, or in the apache module config).

-

I haven’t found a way to post bugs I’ve found in Rails, but I’ve encountered the same problem on both x86 and ppc Gentoo. In both cases, I emerged rubygems 0.8.10 and then ran gem update to get the latest rubygems. From there, I ran gem install rails, and got rails 0.13.1. The problem is, when I try to run the rails command (as a user) I get the following error:
/usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:186:in `const_missing’: uninitialized constant URI (NameError)

This error does not occur when I run rails as root, and I don’t need root to run other gems I have installed (except instiki, which has the same problem, since it uses rails).

ps .There is a problem with fastcgi and zombies. Some people recommend fcgid instead:
http://paul.querna.org/journal/articles/2006/01/01/using-mod_fcgid-for-ruby-on-rails-applications
or lighthttp.