Ruby on Rails
HowToUseOracleWithFastCGI

If you’ve successfully run a Rails controller via CGI, and you use Oracle, and you’re finding that you get a lot of the following messages in your Apache log when you try to switch to FastCGI? via dispatch.fcgi:

[warn] FastCGI: (dynamic) server "/rails/msproj/public/dispatch.fcgi" restarted (pid 2327)
[warn] FastCGI: (dynamic) server "/rails/msproj/public/dispatch.fcgi" (pid 2327) terminated by calling exit with status '0'
[warn] FastCGI: (dynamic) server "/rails/msproj/public/dispatch.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds
[warn] FastCGI: (dynamic) server "/rails/msproj/public/dispatch.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 600 seconds
[

Then you probably need the following in your httpd.conf file:

SetEnv LD_LIBRARY_PATH=/usr/local/oracle/lib
SetEnv ORACLE_HOME=/usr/local/oracle
SetEnv ORACLE_SID=orcl
FastCgiConfig -initial-env CPATH=/usr/include/oracle/10.1.0.3/client -initial-env LD_LIBRARY_PATH=/usr/local/oracle/lib -initial-env ORACLE_HOME=/usr/local/oracle -initial-env ORACLE_SID=orcl

mod_fcgid & mod_fastcgi

If you have already been running rails and have just installed the ruby-oci interface, you may be experiencing the following error:

[notice] mod_fcgid: call /export/home/username/myapp/public/
dispatch.fcgi with wrapper /usr/local/bin/ruby /export/home/username/myapp/public/dispatch.fcgi
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/connection_adapters/oracle_adapter.rb:536: undefined
method `define_a_column' for class `OCI8::Cursor' (NameError)
... 

Here’s how I set up Apache2 and mod_fcgid for Oracle (and optionally mod_fasctgi if you like to switch between both modules). In this case, Oracle connections are defined in /etc/oracle/tnsnames.ora, and the Instant Client library was installed in /usr/local/lib64/oracle/client.

<IfModule mod_fastcgi.c>
    FastCgiConfig -initial-env LD_LIBRARY_PATH=/usr/local/lib64/oracle/client \
                  -initial-env TNS_ADMIN=/etc/oracle
</IfModule>
<IfModule mod_fcgid.c>
    DefaultInitEnv LD_LIBRARY_PATH /usr/local/lib64/oracle/client
    DefaultInitEnv TNS_ADMIN /etc/oracle
</IfModule>

——

I was getting the following error


Error while trying to retrieve text for error ORA-03120
</pre>
Even though I could connect to oracle using sqlplus and through rails app running on webrick on mongrel.
In order to have oracle working with my apache on fcgid i had to add the following to the httpd.conf ( Thouse variables were set in my .bashrc file with the path pertinent to my environment)


  PassEnv LD_LIBRARY_PATH
  PassEnv PATH
  PassEnv TNS_ADMIN
  PassEnv ORACLE_HOME

Note: Passing TNS_ADMIN through DefaultIniitEnv did not work for me, but mentioned above worked fine. Also, some posts suggested that when you get error mentioned above, you need to get rid of all the tabs and blank lines in your tnsnames file.