Ruby on Rails
RailsOnCentos5

This guide is severely outdated. fcgi should (almost) never be used. I don’t have a centos box to make sure a step by step guide works, but the best thing to do woudl be to

——

Note This guide will help you install ruby on rails on centos 5.0 with apache2 using mod_fcgid. This guide may and probably does have errors. Please feel free to correct them!

At the time of this writing, the following software version where used:

-kernel-2.6.18-8.1.1.el5
-httpd-devel-2.2.3-6.el5.centos.1
-httpd-2.2.3-6.el5.centos.1
-ruby-irb-1.8.5-5.el5
-ruby-libs-1.8.5-5.el5
-ruby-mode-1.8.5-5.el5
-ruby-1.8.5-5.el5
-ruby-ri-1.8.5-5.el5
-ruby-rdoc-1.8.5-5.el5
-ruby-devel-1.8.5-5.el5
-mysql-devel-5.0.22-2.1
-mysql-5.0.22-2.1
-mysql-server-5.0.22-2.1
-fcgi-2.4.0
-mod_fcgid.2.1
-rubygems-0.9.2

1. Update and install needed packages

Execute:


cd ~ yum update yum install httpd-devel httpd apr apr-devel apr-util-devel mysql-server mysql mysql-devel yum install ruby ruby-docs ruby-ri ruby-libs ruby-mode ruby-tcltk ruby-irb ruby-rdoc ruby-devel

2. Install fcgi components

Execute:


cd /usr/local/src/ wget http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz</code
tar zxvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
make install
cd /usr/local/src
wget http://superb-west.dl.sourceforge.net/sourceforge/mod-fcgid/mod_fcgid.2.1.tar.gz
tar zxvf mod_fcgid.2.1.tar.gz
cd mod_fcgid.2.1
nano Makefile

-Change top_dir to:


top_dir = /usr/lib/httpd </pre>
—or for 64bit CentOS5:

top_dir = /usr/lib64/httpd </pre>

-Add line to bottom of file:


INCLUDES=-I /usr/include/httpd -I /usr/include/apr-0

Execute:


make make install

3. Install Ruby Gems and required gems.

Execute:


cd /usr/local/src wget http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-0.9.2.tgz
tar zxzf rubygems-0.9.2.tgz
cd rubygems-0.9.2
ruby setup.rb

cd ~
gem update
gem install rails --include-dependencies
gem install fcgi
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

-Select option 3 – mysql 2.7 (ruby)

If the gem install mysql command fails, try the following instead:


gem install mysql -- --with-mysql-include=/usr/include/mysql --with-mysql-lib=/usr/lib/mysql

… or for 64-bit users


gem install mysql -- --with-mysql-dir=/usr/bin/ --with-mysql-lib=/usr/lib64/mysql/ --with-mysql-include=/usr/include/mysql/

Execute:


nano /etc/ld.so.conf.d/mysql-i386.conf

-Add Line To Bottom:


/usr/local/lib </pre>

—and for 64bit CentOS5:
Execute:


nano /etc/ld.so.conf.d/mysql-x86_64.conf

-Add Line To Bottom:


/usr/local/lib64 </pre>

Execute:


/sbin/ldconfig

4. Create test rails application.

Execute:


mkdir /var/www/rails cd /var/www/rails/ rails cookbook chown -R root.apache cookbook/ chmod -R g+r cookbook/ chmod -R g+w cookbook/log/ chmod -R g+w cookbook/tmp/ find /var/www/rails/cookbook/ -type d -exec chmod g+x {} \;

5. Configure Apache and test application.

Execute:


nano /etc/httpd/conf/httpd.conf

-Find the line:


LoadModule cgi_module modules/mod_cgi.so

-After this line add:


LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so

—or for 64bit CentOS5:

LoadModule fcgid_module /usr/lib64/httpd/modules/mod_fcgid.so

-Find the line:


### End of proxy directives.

-After this line add:


<IfModule mod_fcgid.c> SocketPath /tmp/fcgid_sock/ AddHandler fcgid-script .fcgi


-Find the line:


#NameVirtualHost *:80

-And change to:


NameVirtualHost *:80

-Add lines to bottom of file:


<VirtualHost *:80> DefaultInitEnv RAILS_ENV development ServerName dnsnameoripaddress DocumentRoot /var/www/rails/cookbook/public/ ErrorLog /var/www/rails/cookbook/log/apache.log

<Directory /var/www/rails/cookbook/public/> Options ExecCGI FollowSymLinks AddHandler fcgid-script .fcgi AllowOverride all Order allow,deny Allow from all


Execute:


nano /var/www/rails/cookbook/public/.htaccess

-Find the line:


RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

-And change it to:


RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

-Find the line:


AddHandler fastcgi-script .fcgi

-And change it to:


AddHandler fcgid-script .fcgi

Execute:


cd /var/www/rails/cookbook/ ruby script/generate controller mytest nano app/controllers/mytest_controller.rb

-Change entire file to read:


class MytestController < ApplicationController def index render:text => "Hello World!" end end

6. Set Apache and MySQL to start on startup and fireup services.

Execute:


cd ~ chkconfig --level 2345 mysqld on chkconfig --level 2345 httpd on service httpd restart service mysqld restart

7. Setup default passwords for MySQL (Optional)

Execute:


/usr/bin/mysql_install_db /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h HOSTNAME password 'new-password' -p

8. Test application.

-Open in browser:


http://<IP_ADDRESS>/mytest

This is the best most accurate rails guide out there! Good job

I added a few updates for CentOS5 64bit. Whoever is monitoring this wiki page can clarify if any of the info I added is incorrect. It worked for me though. Thanks for a great guide. This was so much easier than anything else I’ve ever found out there.