aaachilless
aaachilless

Reputation: 113

requiring non-core ruby gems for apache cgi scripts

I'm having a hard time setting up Ruby CGI using Apache and RVM. I can execute scripts that require core gems just fine, but I can't require non-core gems and apache generates an error. For example:

#!/usr/bin/env /home/user/.rvm/rubies/ruby-2.1.0/bin/ruby

require 'cgi'
print "Content-type: text/html\n\n"
print 'hello there'

#!/usr/bin/env /home/user/.rvm/rubies/ruby-2.1.0/bin/ruby

require 'cgi'
require 'nokogiri'

print "Content-type: text/html\n\n"
print 'hello there'

both scripts will run just fine from terminal, but apache throws up on the second one, giving this error:

[Tue Mar 25 20:53:13 2014] [error] [client 127.0.0.1] Premature end of script headers: main_index.rb /home/aaachilless/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- nokogiri (LoadError)from /home/aaachilless/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire'from /home/aaachilless/Dropbox/aaachilless-me/cgi/main_index.rb:4:in `'

It looks like this guy How do I get a Ruby CGI program that requires a gem to run properly? was having the same problem, but requiring rubygems doesn't solve it for me.

Any help is appreciated!

Upvotes: 1

Views: 436

Answers (2)

csmartin
csmartin

Reputation: 11

I solved this same problem by executing the ruby wrapper from RVM for the version I was using on the CLI in the shebang instead of just /usr/bin/ruby

#!/usr/local/rvm/wrappers/ruby-2.1.2/ruby

Upvotes: 1

jimworm
jimworm

Reputation: 2741

rvm is applied per-user, so your (system? deploy? root?) user will need to load rvm when it starts up, probably using /etc/profile.d/rvm.sh.

Check out "Multi-user installs" in the rvm docs for guidance.

Upvotes: 0

Related Questions