Ruby, Ruby Gems, Rails and FastCGI Installation

Posted by Miraenda Sun, 04 Jun 2006 04:34:00 GMT

A. Install Ruby (latest source package - http://ruby-lang.org/en/20020102.html):
mkdir /root/setup
cd /root/setup && wget ftp.ruby-lang.org/pub/ruby/ruby-1.8.4.tar.gz
tar -xvzf ruby-*
cd ruby-*
./configure && make && make install

B. Install Ruby Gems (latest version - http://rubyforge.org/frs/?group_id=126):
cd /root/setup && wget rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar -xvzf rubygems-*
cd rubygems-*
ruby setup.rb

C. Install Rails:
gem install rails

(Answer y to all the dependancies)

D. Install FCGI and FastCGI (sourced from http://fastcgi.com/dist/):
cd /root/setup && wget fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar -xvzf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure && make && make install

cd /root/setup && wget fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -xvzf mod_fastcgi-*
cd mod_fastcgi-*
/usr/local/apache/bin/apxs -o mod_fastcgi.so -c *.c
/usr/local/apache/bin/apxs -i -a -n fastcgi mod_fastcgi.so

E. Install Ruby Gems fcgi:
gem install fcgi

F. Edit Apache config file:
vi /etc/httpd/conf/httpd.conf

Find the following (usually I do esc + / and enter SSLL to find this area in httpd.conf file):

SSLLog      /usr/local/apache/logs/ssl_engine_log
SSLLogLevel info

</IfModule>

Enter these lines under the ending </IfModule> line:

<IfModule mod_fastcgi.c>
    FastCgiIpcDir /tmp/fcgi_ipc/
    AddHandler fastcgi-script .fcgi
</IfModule>

Check for the fastcgi apache module entries:
LoadModule fastcgi_module libexec/mod_fastcgi.so
and
AddModule mod_fastcgi.c

G. Make the /tmp/fcgi_ipc/ directory and setup Apache permissions for it:
mkdir -p /tmp/fcgi_ipc
chown nobody:nobody /tmp/fcgi_ipc -R
chmod -755 /tmp/fcgi_ipc -R

H. Install MySQL for Ruby:
gem install mysql

Select option 3 for the installation process.

I. Install PostGRESQL for Ruby (if you have PostGRESQL on your cPanel Dedicated server):
gem install postgres

J. Restart Apache:
/etc/init.d/httpd stop
killall -9 httpd
/etc/init.d/httpd startssl

K. Additional Information:

Please note that user and appname should be replaced by the specific account's cPanel username and the application folder name you want to use for your Rails' application.

a. Make sure Apache can find dispatch.fcgi

Edit your Rails application’s /home/user/appname/public/.htaccess and change the following lines to make sure that the Rails app is using FastCGI.

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

b. Make sure that dispatch.fcgi is executable
chmod 755 /home/user/appname/public/dispatch.fcgi

c. For existing applications:

Make sure that your app lives in /home/user/appname. Add the following lines in your Rails application’s /home/user/appname/public/dispatch.fcgi file:
require 'fcgi'
require 'rubygems'
require_gem 'fcgi'

d. For a new account, you can test Rails doing the following:
cd /home/user
rails appname
cd appname
ruby script/generate controller test
cd /home/user/public_html
ln -s ../appname/public appname

Navigate to http://domain.com/appname/ and you should see a “Congratulations” page!

Posted in  | 5 comments | no trackbacks

Older posts: 1 2 3 4 5 6