installation fcgi with ruby

This is a small how to install  fcgi to work with ruby and rails.

first of all you should have ruby and rails installed on your server. In my case I installed ruby and rails using standard Debian command


apt-get install ruby gem rails


to make sure that you use the latest version of rails I recommend to check installation with gem:


gem install rails


after that I was ready to install fcgi on my server:


cd /temp
wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar -zxvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure --prefix=/usr/local/fcgi --exec-prefix=/usr/local/fcgi
make install


Now you can install the fcgi gem (this is a long command which your browser may line-wrap here -- beware that the command is all on the same line):


gem install fcgi -r -- --with-fcgi-lib=/usr/local/fcgi/lib --with-fcgi-include=/usr/local/fcgi/include


You also need to install the FastCGI module for Apache. Make sure you have Perl installed on your shared host, you need it to run apxs!

cd /temp
wget http://www.fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -zxvf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
/usr/sbin/apxs -o mod_fastcgi.so -c *.c
/usr/sbin/apxs -i -a -n fastcgi mod_fastcgi.so
You may need to add the following block to "/etc/apache2/apache2.conf":
<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
And finally, you need to configure your Rails project to use FastCGI. Edit the file "(your_rails_app)/public/.htaccess", changing the line:
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

You'll need to restart Apache before the changes will take effect:


/etc/init.d/apache2 restart

No comments: