Setup Ruby on Rails behind Apache

Here are some of the ways to run Ruby on Rails behind Apache.

Apache + mod_fcgid

Reference Howto Setup Apache With FastCGI And Ruby Bindings.

Apache mod_fcgid

Make sure mod_fcgid is available, if not, install it
# emerge -pv www-apache/mod_fcgid

Ruby fcgi

I was not able to install it via gem. See error below:

# gem18 install fcgi
Building native extensions.  This could take a while...
ERROR:  Error installing fcgi:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby18 extconf.rb install fcgi
checking for fcgiapp.h... no
checking for fastcgi/fcgiapp.h... no
*** extconf.rb failed ***

It turned out that I didn't have fcgi lib installed. Actually, using emerge could satisfy the boken dependency

# emerge -pv emerge -pv dev-ruby/ruby-fcgi

Another option is to download Ruby fcgi from http://raa.ruby-lang.org/project/fcgi/ and install from source:

# tar xzf ruby-fcgi-0.8.7.tar.gz
# cd ruby-fcgi-0.8.7
# ruby install.rb config
# ruby install.rb setup
# ruby install.rb install

With this option, you also need the fcgi lib. 

Configure apache

There isn't anything we need to do with apache configuration, other than adding "-D FCGID" into APACHE2_OPTS variable in the file /etc/conf.d/apache. The restart apache.

In your project/public/.htaccess file, however, you need to:

  1. Comment out the following lines:
    AddHandler fastcgi-script .fcgi
    AddHandler cgi-script .cgi
    RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
  2. Add a line:
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

Apache + mod_proxy_balancer + Mongrel

Here are some greate reference on how to set it up:

Apache + mod_rails

This is another option to check out. I think it is fairly new. http://modrails.com/. In portage, it is called "www-apache/passenger". "emerge -pv www-apache/passenger" will give you the info.

 

Comments

Hardware

"A wonderful article you posted. That is so informatory and creative. Please keep these excellent posts coming. You helped me so much.

Thanks for sharing!"