Forum

How to install Ruby on Rails

Ricard Forniol Agust
27 July 2007, 20:45
I am interested in use Hiawatha to run rails aplications is it possible and recommendable?

Thanks
Hugo Leisink
28 July 2007, 10:48
How to have Hiawatha run CGI's can be found in the HOWTO [projects.leisink.org].

You probably want something like this in your Hiawatha configuration:
CGIhandler = /usr/bin/ruby:ru

This tells Hiawatha to use the binary /usr/bin/ruby to handle .ru files.


I'm not familiar with Ruby, so I don't know what the "on rails" part means. If the information above is not sufficient, please let me know.


To increase the performance of using Ruby for CGI, is to use FastCGI [projects.leisink.org]. I've seen that Ruby supports FastCGI, but since I'm not familiar with Ruby, I've no idea how to configure Ruby to do so.
Ricard Forniol Agust
28 July 2007, 19:16
Rails is a framework to create database webaplications with ruby.

I create this file to set fcgi configuration, but I don't know where is it called from in php-fcgi.conf case for example.
#ruby-fcgi.conf
Server = cgi-fcgi -start -connect :2005 /var/www/rails/app/public/dispatch.fcgi


#httpd.conf
FastCGIserver {
FastCGIid = RUBY
ConnectTo = localhost:2005
Extension = rb
SessionTimeout = 30
}

VirtualHost {
Hostname = www.app.dev
WebsiteRoot = /var/www/rails/app/public
StartFile = dispatch.fcgi
AccessLogfile = /usr/local/var/log/hiawatha/access.log
ErrorLogfile = /usr/local/var/log/hiawatha/error.log
ExecuteCGI = yes
FastCGI = RUBY
}


Thanks
Hugo Leisink
28 July 2007, 20:26
I create this file to set fcgi configuration, but I don't know where is it called from in php-fcgi.conf case for example.
#ruby-fcgi.conf
Server = cgi-fcgi -start -connect :2005 /var/www/rails/app/public/dispatch.fcgi


php-fcgi.conf is used by php-fcgi, which comes with Hiawatha. php-fcgi is a tool to start PHP as a FastCGI daemon. ruby-fcgi.conf is not used by Hiawatha, but I will think of something to support FastCGI programs other that PHP.

For now: you'll have to start cgi-fcgi manually.

#httpd.conf
FastCGIserver {
FastCGIid = RUBY
ConnectTo = localhost:2005
Extension = rb
SessionTimeout = 30
}

VirtualHost {
Hostname = www.app.dev
WebsiteRoot = /var/www/rails/app/public
StartFile = dispatch.fcgi
AccessLogfile = /usr/local/var/log/hiawatha/access.log
ErrorLogfile = /usr/local/var/log/hiawatha/error.log
ExecuteCGI = yes
FastCGI = RUBY
}


This looks good, but maybe you want to add 'fcgi' to the Extension in the FastCGIserver block:
FastCGIserver {
...
Extension = rb, fcgi
}

Note that the SessionTimeout is only necessary when you use more than one ConnectTo parameter (load balanced FastCGI), but it will not harm if you don't (it will be ignored by Hiawatha in this configuration).

I really like to know what you think of Hiawatha. Things you like and especially things you don't like. So I can improve Hiawatha. Please give me some feedback about your Hiawatha experiences. Thanks in advance.
Ricard Forniol Agust
29 July 2007, 21:05
I'm trying to connect to fcgi but I can't.

I did a netstat and there's nothing listening on port 2005, but process remains running. Then I tried with a sock and it apears in netstat, but the problem was sintactical. I don't know (if it's possible) how to indicate it in the ConnectTo.


It doesn't work:
ConnectTo /tmp/fcgi.sock


I'm using openbsd 4.1 to make this tests.


I have another question... is possible to use rewriting url?
dispatch.fcgi?controller=admin&action=login becomes /admin/login


Thanks
Hugo Leisink
30 July 2007, 00:30
The tool cgi-fcgi [www.fastcgi.com] can be used to turn a non-daemon FastCGI application into a FastCGI daemon. A requisite is that the FastCGI toolkit [www.fastcgi.com] has been used to create the FastCGI application.

The ConnectTo takes a <hostname>:<port> as a parameter.

Hiawatha has no URL rewrite abilities. You can use a ErrorHandler = 404:/rewrite.cgi and let the rewrite.cgi application take care of your URL rewrites.
Hugo Leisink
30 July 2007, 09:42
I've made the following example program and named it 'test.ru':
#!/usr/bin/ruby

require "fcgi"

FCGI.each_cgi {|cgi|
puts "Content-Type: text\plain\r\n\r\n"

output = cgi.env_table['REQUEST_METHOD'] + " " + cgi.env_table['REQUEST_URI']
if cgi.env_table['QUERY_STRING'] != nil
output += "?" + cgi.env_table['QUERY_STRING']
end
output += " " + cgi.env_table['SERVER_PROTOCOL']

puts output
}

I've started it with: cgi-fcgi -start -connect :2010 ./test.ru

I've used the following Hiawatha configuration:
FastCGIserver {
FastCGIid = RUBY
ConnectTo = 127.0.0.1:2010
Extension = fcgi
}

VirtualHost {
Hostname = rubytest.lan
...
StartFile = index.fcgi
FastCGI = RUBY
}

Every request for a .fcgi file in http://rubytest.lan/ goes via my test.ru FastCGI daemon and will print "Ruby FastCGI works!"

This example shows that FastCGI Ruby under Hiawatha works. I hope this example is usefull to you. If not, let me know.
Ricard Forniol Agust
2 August 2007, 23:26
My problem is to execute it:
cgi-fcgi -start -connect :2010 ./test.ru

It finishes without any error and nothing is listening on port 2010.

I can only execute it with a sock, but it is not suported
Hugo Leisink
3 August 2007, 12:19
It finishes without any error and nothing is listening on port 2010.


Try using #!/usr/local/bin/ruby on the first line of the test.ru script. OpenBSD has ruby installed in /usr/local/bin, not in /usr/bin.
This topic has been closed.