TvE 2100

At 2100 feet above Santa Barbara

Installing Ruby on Rails, MySQL, FastCGI, and Lighttpd on Fedora Core 5

I spent the better part of the day installing ruby on rails on a fresh minimal fedora core 5 system. After a lot of back and forth I finally found a “HowTo”:http://www.digitalmediaminute.com/howto/fc4rails/ that I then followed. That helped a lot. Here is my recollection of what I did:

Installing a whole bunch of ruby stuff:

@yum install ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs@

Installing gems:

wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar zxvf rubygems-0.8.11.tgz
cd rubygems-0.8.11
ruby setup.rb

I eventually discovered I didn’t have GCC installed, that lead to:

@yum groupinstall “Development Tools”@

which was probably more than I bargained for.

I installed rails:

@gem install rails –include-dependencies@

And the ruby mysql interface:

@gem install mysql@

Now mySQL:

@yum install mysql-server@

I changed the data directory for mysql as specified in /etc/my.cnf as follows for the install of typo that I was doing:

[mysqld]
datadir=/home/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
     
[mysql.server]
user=mysql
basedir=/home

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Made mysql to start on boot-up and started it:

chkconfig --add mysql
chkconfig --level 3 mysqld on
/etc/init.d/mysqld start

Next I set the root DB password, created a database and a user for typo, and gave the appropriate permissions. I finally initialized the database:

mysqladmin -u root password 'xxyyzz'
mysqladmin -u root -p create 'typo'
mysql --user=root -p mysql
  create user 'typo'@'localhost' identified by 'yyaaxx';
  grant all on typo.* to 'typo'@'localhost';
mysql -u typo -p -D typo 


Ok, lighttp came next, together with its fastCGI interface:

yum install lighttpd
yum install lighttpd-fastcgi
chkconfig --add lighttpd
chkconfig --level 3 lighttpd on

Then editing its config file (only changed lines shown):

server.document-root        = "/home/typo/rails/public/"
index-file.names            = ( "dispatch.fcgi", "index.html",
                                "index.htm", "default.htm" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
server.error-handler-404   = "/dispatch.fcgi"
server.username             = "typo"
server.groupname            = "typo"
fastcgi.server             = ( ".fcgi" =>
                               ( "localhost" =>
                                 (
                                   "socket" => "/tmp/rails.socket",
                                   "bin-path" => "/home/typo/rails/public/dispat
ch.fcgi",
                                   "min-procs" => 1,
                                   "max-procs" => 2
                                 )
                               )
                            )
url.rewrite = ( 
        "^/$" =>  "/dispatch.fcgi?controller=home&action=index2",
        "^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9%]+)\??([\-_a-zA-Z0
-9=&%]*)$"  => 
                "/dispatch.fcgi?controller=$1&action=$2&id=$3&$4",
        "^/([\-_a-zA-Z0-9]+)/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$"  => 
                "/dispatch.fcgi?controller=$1&action=$2&$3",
        "^/([\-_a-zA-Z0-9]+)/?\??([\-_a-zA-Z0-9=&%]*)$"  =>  
                "/dispatch.fcgi?controller=$1&action=index&$2"
)

Finally the ruby fcgi library:

@gem install fcgi@

Now running WEBrick worked fine:

rails testapp
cd testapp
scripts/server

But lighttpd didn’t. The error that kept me busy for a long time was:

[01/Jun/2006:17:12:18 :: 7093] Dispatcher failed to catch: undefined method `is_cgi?' for FCGI:Class (NoMethodError)
  /usr/lib/site_ruby/1.8/fcgi.rb:593:in `each_cgi'
  /home/typo/rails/public/../config/..//vendor/rails/railties/lib/fcgi_handler.rb:52:in `process!'
  /home/typo/rails/public/../config/..//vendor/rails/railties/lib/fcgi_handler.rb:22:in `process!'
  /home/typo/rails/public/dispatch.fcgi:25
almost killed by this error

I eventually figured out the solution:

echo /usr/local/lib >/etc/ld.so.conf.d/local.conf
ldconfig -v

And there, restarted lighttpd, and it all worked. Phew!