Working with mod_ruby
11 April 2007
While working with mod_ruby over the past week, I put together a small list of tips which might help other beginners like me...
403 Forbidden Error
After successfully installing mod_ruby, I would get a "403 Forbidden" error when attempting to run a ruby script. My apache log file showed..
[Wed Apr 11 10:32:13 2007] [error] access to /var/www/ruby/ruby.rb failed for (null), reason: Options ExecCGI is off in this directoryI simply added "Options +ExecCGI" to my httpd.conf file like so...
<Files *.rb>
Options +ExecCGI
SetHandler ruby-object
RubyHandler Apache::RubyRun.instance
</Files>I was still getting a 403 error when running the script, but my apache logs were now reporting that the file permissions were incorrect. Easy fix, I chmod'd the file to 777, and the test script worked perfectly.
Incorrect HTTP Headers
I found that I could change the content type from text/plain to text/html by using this code...
r = Apache.request
r.content_type = 'text/html'
r.send_http_header
exit(Apache::OK) if r.header_only?There are other solutions to this problem.Changes in included files not taking effect
mod_ruby caches scripts included using 'require'. Using 'load' instead will force mod_ruby to reload the included script.
Fetching GET variables
variable = Apache.request.paramtable['variable']