FastCGI is a language independent, webserver-independent, scalable, open extension to CGI that provides high performance without the limitations of server specific APIs.
If you are using Apache you will need mod_fcgi, and the FastCGI? Development kit; These can be obtained from http://www.fastcgi.com . You will also need ruby-fcgi.
Note that official FastCGI with Apache 2 is considered unreliable, a prefered module for use with Apache 2 and up, mod_fcgid can be found here: http://fastcgi.coremail.cn/
(Also found in major package systems)
You can do the install manually or using your package manager.
emerge fcgi ruby-fcgi mod_fastcgi
apt-get install libapache-mod-fastcgi libfcgi-ruby1.8
$ wget <a href="http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz">www.fastcgi.com/dist/fcgi-2.4.0.tar.gz</a> $ tar zxvf fcgi-2.4.0.tar.gz $ cd fcgi-2.4.0 $ ./configure $ sudo make install
$ sudo apt-get install libfcgi-dev $ sudo gem install fcgi
$ sudo gem install fcgi -- --with-fcgi-include=/usr/local/include --with-fcgi-lib=/usr/local/lib
LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so <IfModule mod_fastcgi.c> FastCgiIpcDir /tmp/fcgi_ipc/ AddHandler fastcgi-script .fcgi </IfModule>
$ apache2ctl reload
require 'fcgi'
require 'rubygems' require_gem 'fcgi'
$ sudo gem update
RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]
thanks to ((Jarkko Laine))
For me (Mefiboset) this did not work, I used this instead:
RewriteRule ^(.*)$ /dispatch.fcgi$1 [L]
If your app (or an opensource app like typo or hierarki) is working fine using a webbrick server normaly started with:
$ ./script/server -e production
ENV['RAILS_ENV'] ||= 'production'
It took me a long night without sleep to find this out.
Also note that testing dispatch.fcgi from the command line can reveal interesting errors:
$ public/dispatch.fcgi
If you get Ruby errors you should fix these first, however if you see a
Status: 500 Internal Server Error
If you get errors
If you get in your log files something along the lines of “dispatch.fcgi has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds” then you need to edit public/dispatch.fcgi and dispatch.rb to change the location of ruby on the first line to the correct location on your deployment machine – this is especially important if you’ve developed on Windows and are deploying on Unix
If you get error: undefined method `is_cgi?’
because native fcgi.so not loaded correctly.
fcgi.so depends on libfcgi.so.0
add this to /etc/ld.so.conf:
/usr/local/lib
then type: /sbin/ldconfig
retry again
Side Note: The above says to use apachectl or apache2ctl to restart apache. However, several linux distros use scripts in /etc/init.d to control daemon processes like apache. If you have such a directory, check to see if there’s an apache script in there!.