Topic: Running mod_ruby

Hi, I'm having trouble running my application with mod_ruby on Apache2. I've set them up like this:


httpd.conf:
-----------

<IfModule mod_ruby.c>
  RubyRequire apache/ruby-run
  RubySafeLevel 0
  <Location /instrumenta>
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  </Location>
</IfModule>


public/.htaccess:
-----------
RewriteRule ^(.*)$ dispatch.rb [QSA,L]


And when I run the app I get the awful error msg:
"Application error
Rails application failed to start properly"


And the Apache logs show me this:

------------------------
[Tue Sep 05 18:22:01 2006] [error] mod_ruby: error in ruby
[Tue Sep 05 18:22:01 2006] [error] mod_ruby: /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in `const_missing': uninitialized constant ADDITIONAL_LOAD_PATHS (NameError)
[Tue Sep 05 18:22:01 2006] [error] mod_ruby:   from /var/rails/instrumenta/public/dispatch.rb:12
[Tue Sep 05 18:22:01 2006] [error] mod_ruby:   from /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:140:in `load'
[Tue Sep 05 18:22:01 2006] [error] mod_ruby:   from /usr/lib/ruby/1.8/apache/ruby-run.rb:53:in `handler'
------------------------

Please help, I'm stuck and need to get this working asap.
Thanks a lot.

-Ofir

Re: Running mod_ruby

Do you get the same const_missing error if you run the dispatch.rb file directly from the command line?

ruby /path/to/public/dispatch.rb

Railscasts - Free Ruby on Rails Screencasts

Re: Running mod_ruby

I'll try it as soon as I get to work tomorrow morning. Thanks!

Re: Running mod_ruby

Are you sure your rewrite rule points to RAILS_ROOT/public/dispatch.rb?

Re: Running mod_ruby

ryanb wrote:

Do you get the same const_missing error if you run the dispatch.rb file directly from the command line?

ruby /path/to/public/dispatch.rb

Yes, I do get the same error, but this time obviously the apache logs don't show me the const_missing error. I only get the browser error:

#ruby /var/rails/instrumenta/public/dispatch.rb

Status: 500 Internal Server Error
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
  <h1>Application error</h1>
  <p>Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html</p>
</body>


I tried looking at the logs inside the rails app and they don't show anything either.
What can I do?

Re: Running mod_ruby

cwd wrote:

Are you sure your rewrite rule points to RAILS_ROOT/public/dispatch.rb?

I didn't know my rewrite rule had to point to that place, this is what I have in my public/.htaccess file:

Options +FollowSymLinks +ExecCGI

RewriteEngine On

RewriteBase /instrumenta
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.rb [QSA,L]

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"


Am I doing anything wrong here?

Re: Running mod_ruby

Sorry about having you run dispatch.rb directly. I guess that doesn't report the error like I expected it to. Try running script/server and see if you get the error through that.

Also, in the dispatch.rb file there's a comment about changing "require 'dispatcher'" to an absolute path for performance reasons. If you've already changed it, I would try changing it back to 'dispatcher' and see if you get the same error. Or if you haven't changed it, try setting it to an absolute path.

Last edited by ryanb (2006-09-06 11:46:50)

Railscasts - Free Ruby on Rails Screencasts

Re: Running mod_ruby

It doesn't give me any output on script/server, since I'm trying to setup mod_ruby on Apache2, and script/server is Webrick.

I've done all sorts of combinations changing the dispatcher line to relative and absolute paths and it doesn't work.

I'm sick of rails now, the framework is ok, but until there's a proper, safe and stable way to run it I'm sticking to PHP or JSPs.

Anyway, thanks a lot for your help, I do appreciate it.

-Ofir

Re: Running mod_ruby

ofir wrote:

It doesn't give me any output on script/server, since I'm trying to setup mod_ruby on Apache2, and script/server is Webrick.

Oh, it was my understanding that an Apache2/mod_ruby setup wouldn't interfere with Webrick, but I've honestly never tried it.

ofir wrote:

I'm sick of rails now, the framework is ok, but until there's a proper, safe and stable way to run it I'm sticking to PHP or JSPs.

Yeah, deployment is one area that can be really painful in Rails, especially with Apache2 and mod_ruby. Actually FastCGI is preferred over mod_ruby, you might want to try Mongrel as well.

Sorry to hear you've had such a bad experience with it. The advantages I get from the Rails framework far outweigh the pain of deployment IMO.

Railscasts - Free Ruby on Rails Screencasts

Re: Running mod_ruby

I wanted to try using mod_ruby, since FCGI has an annoying bug I can't get fixed. I even posted a thread about it http://www.sitepoint.com/forums/showthread.php?t=417678
I can't use Mongrel or any other proxy solution, since I'm using client auth in Apache, and it would be pointless since the app could be accessed directly thru http://server:5000 or so.
I think Rails is a very good framework, I'm just not sure it's ready to be used for more complicated projects than building a blog. It seems a waste having such a great software running on such a lousy deployment platform, hope this gets addressed asap.

11

Re: Running mod_ruby

I'm sure you can set it up on your server so requests to port 5000 or whatever are denied unless coming from localhost.

ofir wrote:

I'm just not sure it's ready to be used for more complicated projects than building a blog

yeah it sucks for non blog sites neutral

vinnie - rails forum admin