As many others I also got interested in new mod_rails deployment solution for Rails applications. And when I read how to use it for development environment needs I decided to try it out.
As you probably know I am using Mac for development and using Oracle database for many Rails applications. So if you do it as well then at first you need to setup Ruby and Oracle on your Mac.
After that I installed and did setup of mod_rails according to these instructions and these additional notes.
One additional thing that I had to do was to change the user which will be used to run Apache httpd server as otherwise default www user did not see my Rails applications directories. You should do it in /etc/apache2/httpd.conf:
User yourusername Group yourusername
And then I started to fight with the issue that ruby which was started from mod_rails could not load ruby-oci8 library as it could not find Oracle Instant Client shared library. And the reason for that was that mod_rails launched ruby with very minimal list of environment variables. E.g. as DYLD_LIBRARY_PATH environment variable was not specified then ruby-oci8 could not find Oracle Instant Client libraries.
The issue is that there is no documented way how to pass necessary environment variables to mod_rails. Unfortunately mod_rails is ignoring SetEnv settings from Apache httpd.conf file. Therefore I needed to find some workaround for the issue and finally I did the following solution.
I created executable script file /usr/local/bin/ruby_with_env:
#!/bin/bash export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2:$DYLD_LIBRARY_PATH" export SQLPATH=$DYLD_LIBRARY_PATH export TNS_ADMIN="/usr/local/oracle/network/admin" export NLS_LANG="AMERICAN_AMERICA.UTF8" /usr/bin/ruby $*
and then in Apache httpd.conf file I changed RailsRuby line to
RailsRuby /usr/local/bin/ruby_with_env
As a result in this way I was able to specify necessary environment variables before Ruby and Rails was started and after this change ruby-oci8 libraries were successfully loaded.
You can use this solution also on Linux hosts where you will deploy Rails applications in production.
Currently I still have issue with mod_rails that it fails to execute RMagick library methods (which is compiled with ImageMagick). I get strange errors in Apache error_log:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug. [error] [client ::1] Premature end of script headers:
When I was running the same application with Mongrel then everything was running correctly. If anyone has any ideas what could be the reason please write some comment.

After full recompilation of ImageMagick and RMagick (according to these instructions) I achieved that mod_rails started to work with RMagick. Don’t know the reason :)
Comment by Raimonds Simanovskis — May 25, 2008 @ 10:20 pm |
rails 2.1 is out, did you already realize the oracle “lob locking” problem that got introduced with the release?
Comment by Roob — June 2, 2008 @ 12:17 pm |
@Roob – no, I have not yet tried Rails 2.1 with Oracle. Would be nice if you could provide more details about this issue so that I could investigate it.
Comment by Raimonds Simanovskis — June 3, 2008 @ 8:32 am |
Rails 2.1 + ActiveRecordStore = crash
ORA-22920: row containing the LOB value is not locked
with partial updates turned off it seems to work fine
CGI::Session::ActiveRecordStore::Session.partial_updates = false
Comment by ebei — June 17, 2008 @ 3:33 pm |
I’ve put
CGI::Session::ActiveRecordStore::Session.partial_updates = false
on environment.rb but I still get ORA-22920
Comment by Guilherme — July 22, 2008 @ 7:52 pm |
Guilherme, make sure you restart the server after making this change to turn partial updates off.
Also, I had to add this to the end of the environment.rb file.
Comment by Larry Gebhardt — September 3, 2008 @ 7:00 pm |
Actually now you can just gem install latest version of activerecord-oracle_enhanced-adapter and you should not do any patching of session store class – now I have fixed that partial model updates that were introduced in Rails 2.1 work correctly with oracle_enhanced adapter.
Comment by Raimonds Simanovskis — September 4, 2008 @ 10:46 am |
You are a life-saver! Thanks
Comment by Mr Frosti — September 17, 2008 @ 12:39 am |
We didn’t want to do this as it required a different setup for dev & production. We developed a very simple patch for PaperClip to introduce a parameter to set the MAGICK_HOME environment variable. See http://thoughtbot.lighthouseapp.com/projects/8794-paperclip/tickets/109-phusion-passenger-mod_rails-issue-on-osx for more details.
Comment by Mat — February 15, 2009 @ 2:34 am |
You can set environment variables from Ruby using ENV[...]= only if some other Ruby library is accessing this environment variable.
But if some external library needs this environment variable then you need to set it before you start Ruby (therefore in my case I did this workaround with wrapper script).
In addition I found out other way how to set up additional environment variables for Apache both on Mac OS X and Linux – see http://wiki.github.com/rsim/oracle-enhanced/troubleshooting for details.
Comment by Raimonds Simanovskis — February 15, 2009 @ 12:02 pm |
Thanks for this elegant work around. Works a treat.
Comment by Paul Gillespie — May 4, 2009 @ 12:24 pm |
A similar process is needed to get this working with lighttpd or it will complain about not being able to find the oracle oci8 libs.
I created the script as above, placed in /usr/local/bin/ and made it executable.
To get this loaded by lighttpd, I changed the first line of rails_app/public/dispatch.fcgi from
#!/usr/bin/ruby1.8
to
#!/usr/local/bin/ruby_with_env
I’m not sure if this is the best way to do this, but it wont be needed (for me) in production, and it works, so I’m happy with it.
Dave
Comment by Dave Smylie — September 18, 2009 @ 4:04 am |