about img
blogger img

UnderPaidLoveMonkis posts img

Corys posts image

buchos posts img

scotts posts image


HowTo: Install FastCGI and Ruby on Rails on Redhat Enterprise

UnderpaidLoveMonki @ 9:26 pm January 14th, 2006

Here’s a quick guide (written on scratch paper, but now published in this blog, so packages may be newer now) how I got Ruby on Rails and FastCGI for Apache2 running in Redhat Enterprise Linux ES release 4 (Nahant Update 2) on a production Dell PowerEdge server.

Note: This works on my box. So YMMV and use it at your own risk. I’m not responsible nor will troubleshoot your problems if they arise.

Because of its packages are a bit dated and needed newer versions to run my rails applications, this is what I did to get the newer packages installed on this box.

Package dependencies needed to be downloaded from Redhat’s repositories

Update your packages first by: sudo up2date –nox -u on the terminal console.
1) gcc-3.4.4-2 (sudo up2date -i gcc)
2) httpd-2.0.52-19.ent (Apache2)
httpd-devel-2.0.52-19.ent
3) mysql:
mysqlclient10-3.23.58-4.RHEL4.1
mysql-devel-4.1.12-3.RHEL4.1
mysql-4.1.12-3.RHEL4.1
mod_auth_mysql-2.6.1-2.2
libdbi-dbd-mysql-0.6.5-10.RHEL4.1
mysql-server-4.1.12-3.RHEL4.1

1) Install Ruby
a) $ wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.3.tar.gz (latest stable at the time of writing)
b) $ tar zxvf ruby-1.8.3.tar.gz
c) $ cd ruby-1.8.3
d) $ sudo ./configure
e) $ make
f) $ sudo make install

To check if ruby compiled and installed correctly, type:
$ ruby -v

If installed correctly, you should see:
ruby 1.8.3 (2005-09-21) [i686-linux]

2) Install RubyGems
a) $ wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
b) $ tar zxvf rubygems-0.8.11.tgz
c) $ cd rubygems-0.8.11
d) $ sudo ruby setup.rb

To check if ruby compiled and installed correctly, type:
$ gem -v

If installed correctly, you should see:
0.8.11

e) $ gem list (prints list of gem packages installed)
f) $ sudo gem update --system (updates your gem package)

3) Install Rails using RubyGems
a) $ gem update
b) $ sudo gem install rails –source http://gems.rubyonrails.com –include-dependencies

To check if ruby compiled and installed correctly, type:
$ rails -v

If installed correctly, you should see:
Rails 1.0.0

4) Install Rails-MySQL
a) $ gem update
b) $ sudo gem install mysql

NOTICE: if you get an error such as this:

$ sudo gem install mysql

 Attempting local installation of 'mysql'
Local gem file not found: mysql*.gem
Attempting remote installation of 'mysql'
Updating Gem source index for: http://gems.rubyforge.org
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (RuntimeError)
ERROR: Failed to build gem native extension.
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
ruby extconf.rb install mysqlnchecking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no

Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out

SOLUTION:

$ cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/
$ ruby extconf.rb –with-mysql-config=/usr/bin/mysql_config
$ gem install mysql

SOURCE: http://ocsforums.com/showthread.php?p=462

6) Install FastCGI
a) wget http://fastcgi.com/dist/fcgi-2.4.0.tar.gz
b) tar zxvf fcgi-2.4.0.tar.gz
c) cd fcgi-2.4.0
d) sudo ./configure && make && make install

7) Install mod_fastcgi for Apache2
a) wget http://fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
b) tar zxvf mod_fastcgi-2.4.2.tar.gz
c) cd mod_fastcgi-2.4.2
d) $ cp Makefile.AP2 Makefile
e) edit Makefile from:
top_dir = /usr/local/apache2
to:
top_dir = /usr/lib/httpd (where apache2 is installed)
f) $ make
g) $ sudo make install
h) Add entry to httpd.conf:

LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi

i) Restart apache2:
$ sudo /etc/init.d/httpd restart
j) In your rails application directory inside public/.htaccess, change:
RewriteRule ^(.*)$ /dispatch.cgi?$1 [QSA,L]
to
RewriteRule ^(.*)$ /dispatch.fcgi?$1 [QSA,L]
k) Change permissions for user apache.apache:
chmod 755 .htaccess
chmod 755 dispatch.fcgi
l) Had to change dispatch.fcgi from:
#!/usr/bin/ruby1.8
to
#!/usr/local/bin/ruby

My Apache2 Benchmark with FastCGI:

 underpaidlovemonki@amazonjungle.info:~$ ab -n 100 -c 1020 http://underpaidlovemonki.amazonjungle.info
This is ApacheBench, Version 2.0.41-dev < $Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking underpaidlovemonki.amazonjungle.info (be patient)…..done

Server Software:        Apache
Server Hostname:        underpaidlovemonki.amazonjungle.info
Server Port:            80

Document Path:          /
Document Length:        256 bytes

Concurrency Level:      1020
Time taken for tests:   0.127892 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      52520 bytes
HTML transferred:       26624 bytes
Requests per second:    781.91 [#/sec] (mean)
Time per request:       1304.498 [ms] (mean)
Time per request:       1.279 [ms] (mean, across all concurrent requests)
Transfer rate:          398.77 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:       56   56   1.0     57      58
Processing:    11   37  16.0     36      63
Waiting:       10   35  16.0     34      62
Total:         67   94  15.9     93     119
WARNING: The median and mean for the initial connection time are not within a normal deviation
These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
50%     93
66%    104
75%    109
80%    111
90%    116
95%    118
98%    119
99%    119
100%    119 (longest request) 

10 Responses to “HowTo: Install FastCGI and Ruby on Rails on Redhat Enterprise”

  1. Rails Tips | Installing Ruby on Rails on a Redhat Enterprise Linux server Says:

    […] Rob Smirtin sent in (our first!) tip with another detailed Rails installation guide. This one, written by the same person who wrote the Ubuntu guide, is for installing Ruby on Rails on a Redhat Enterprise Linux box. […]

  2. Benjamin Sims Says:

    Tiny note - the update command in f is

    gem update –-system (two dashes rather than one).

    Might save someone 60 seconds with gem help!

    Thanks for the HowTo

  3. UnderpaidLoveMonki Says:

    Funny that in the WordPress code, there are in fact two dashes but in the actual post, only one of the dashes show up. :O

  4. Administrator Says:

    hmm we need to get a plugin for posting code and such.

  5. Charles Aulds Says:

    I’m not sure if it’s a misprint or not, but I believe the optional command line switches to the command may need to be specified with TWO hypens (instead of -with-mysql-config, I had to specify –with-mysql-config). There was no warning that the command line switch had been ignored, which cost me time:

    [root@Python mysql-2.7]# ruby extconf.rb -with-mysql-config
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lm… yes
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lz… yes
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lsocket… no
    checking for mysql_query() in -lmysqlclient… no
    checking for main() in -lnsl… yes
    checking for mysql_query() in -lmysqlclient… no
    [root@Python mysql-2.7]# ruby extconf.rb –with-mysql-config
    checking for mysql_ssl_set()… no
    checking for mysql.h… yes
    creating Makefile

  6. Bryce Kerley Says:

    This is a rockin’ guide. I got it running on the FC4 server at work with this. Thanks for writing it.

  7. J Ditty Says:

    Ditto that.  Used it for FC4 to fix the mysql binding error.  Nice!

  8. Daniel Says:

    Thank you SO much for this:
    SOLUTION:

    $ cd /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/
    $ ruby extconf.rb –with-mysql-config=/usr/bin/mysql_config
    $ gem install mysql

  9. Daniel Says:

    What would the httpd.conf entry look like? Below is an example from the book, “Agile Web Development with Rails”:
    *************

    ServerName http://www.depot.com
    DocumetRoot /path/application/public/
    ErrorLog /path/application/log/server.log

    Options ExecCGI FollowSymLinks
    AllowOverride all
    Allow from all
    Order allow, deny

    *************
    Would I need to make any changes (other than the obvious path changes) to get this to work with FastCGI?

    Thanks, and WONDERFUL HowTo!

  10. bruno Says:

    Ditto on the dashes formatting screwing me up:

    $ ruby extconf.rb –with-mysql-config=/usr/bin/mysql_config

    should be

    $ ruby extconf.rb –with-mysql-config=/usr/bin/mysql_config
    (note: two dashes after extconf.rb and before with-mysql-config=/usr/bin/mysql_config)

Leave a Reply

Subscribe without commenting