要求apache cgi脚本使用非核心ruby gems

时间:2014-03-26 04:08:48

标签: ruby apache gem

我很难使用Apache和RVM设置Ruby CGI。我可以执行需要核心宝石的脚本,但我不能要求非核心宝石,而apache会产生错误。例如:

#!/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'

这两个脚本都可以从终端运行得很好,但apache会在第二个脚本上运行,从而出现此错误:

[Tue Mar 25 20:53:13 2014] [error] [client 127.0.0.1]脚本标题的提前结束: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:in要求'来自/ home / aaachilless / Dropbox / aaachilless-me / cgi / main_index.rb:4:在`'

看起来像这个人How do I get a Ruby CGI program that requires a gem to run properly? 有同样的问题,但要求rubygems并不能解决它。

感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

我通过从RVM执行ruby包装器解决了同样的问题,因为我在shebang的CLI上使用的版本而不仅仅是/ usr / bin / ruby​​

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

答案 1 :(得分:0)

rvm是按用户应用的,因此您的(系统?部署?root?)用户需要在启动时加载rvm,可能使用/etc/profile.d/rvm.sh

the rvm docs中查看“多用户安装”以获取指导。

相关问题