This whole week, I was frustrated trying to make RoR app. run in Apache 2 with FastCGI. I setup couple of instances of linux as virtual machines (mainly Fedora 8/9 and openSUSE 11) and banged on them. So here is what I come up with to make ror apps run in apache 2 with fastcgi… I hope it helps all the poor souls out there…
- Install Apache 2
- Install ruby
$ yum install ruby - Install ruby gems
$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
$ tar xzf rubygems-1.2.0.tgz
$ cd rubygems-1.2.0
$ ruby setup.rb - Install Ruby on Rails
$ gem install rails –include-dependencies - Install httpd devel package
$ yum install httpd-devel - Install FastCGI
$ wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
$ tar xzf fcgi-2.4.0.tar.gz
$ cd fcgi-2.4.0
$ ./configure
$ make
$ make install - Install mod_fcgid
$ wget http://nchc.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.2.tgz
$ tar -zxvf mod_fcgid.2.2.tar.gz
$ cd mod_fcgid.2.2In Makefile file set top_dir to the top path of the apache installation e.g. /etc/httpd
$ make
$ make install - Install FCGI gem
$ yum install ruby-devel
$ gem install fcgi
$ yum install fcgi-devel - Configure apache (httpd.conf)
-
- Add LoadModule fcgid_module modules/mod_fcgid.so
- DocumentRoot “/var/www/html/<app-name>/public”
- <Directory “/var/www/html/<app-name>/public”>
- Inside <Directory> apply these changes
AllowOverride All
Options +FollowSymLinks
Options -Includes -ExecCGI
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
Options +FollowSymLinks +ExecCGI
</IfModule>
#fcgi
FCGIWrapper “/usr/bin/ruby /var/www/html/<app-name>/public/dispatch.fcgi” .fcgi
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
- Install sqlite3
$ yum install sqlite3
$ yum install ruby-sqlite3 - Troubleshoot
If you get “You don’t have permission to access /dispatch.fcgi on this server.” or/and
if you see an error similar to below in apache error log:[error] (13)Permission denied: mod_fcgid: couldn’t bind unix domain socket /etc/httpd/logs/fcgidsock/5093.5
[warn] (13)Permission denied: mod_fcgid: spawn process /var/www/html/poc/public/dispatch.fcgi errorThen check permission/ownership of /fcgidsock/ directory…