Sunday, July 1, 2007

mod_ruby on CentOS-5

I was trying to install mod_ruby on my CentOS-5 today and that seemed to be a bit tricky. First of all, as far as I know, CentOS does not have a prebuilt mod_ruby package. That leaves little other options than compiling the package from source. I found this page, containing a howto for CentOS-3, but it didn't quite work on CentOS-5.



I found that after having installed the httpd-devel, ruby-devel, ruby and httpd packages on CentOS-5, simply running ./configure does not do the trick. One needs to run ./configure.rb --with-apxs=/usr/sbin/apxs --with-apr-includes=/usr/include/apr-1 in order to have the install script find the proper header files. Running the make command after that gives a succesfull build againt both /usr/include/httpd and /usr/include/apr-1 for some reason.



Then, put the following in /etc/httpd/conf.d/ruby.conf:




RubySafeLevel 0

# If you use RubyGems

RubyRequire rubygems

RubyRequire apache/rails-dispatcher

RubyTransHandler Apache::RailsDispatcher.instance



SetHandler ruby-object

RubyHandler Apache::RailsDispatcher.instance

RubyOption railsuriroot /ruby-application-name

RubyOption rails_root /path/to/rails/root

RubyOption rails_env production




(Thanks to carl at the above mentioned page for this!)



Carl's howto puts all this text in httpd.conf. This works, but better stay consistent with the way CentOS handles things. Also, the howto on carl's page has the require line for rubygems commented out. Take special care to require rubygems though! CentOS has no packages for rails, so it's safe to assume you have installed rails from gems. If you do not require rubygems, the setup will silently fail (unless you go through /var/log/httpd/error_log).



I have yet to test this, but it should work nicely.



Update: Well, I cheered too soon. What seems to be the problem is some incompatibility between the (quite old) version of modruby available for download and my (quite recent) version of rails. Probably solvable, but I don't really feel like it. Besides, I decided that it will be much more convenient to use modproxy on Apache and place several of my home-brew rails applications behind it. I'll post a nice how-to for that some day.