抬头,ruby n00b 试水——
操作系统 - OSX 10.7
/Library/WebServer/CGI-Executables 中的 test.rb:
#!/usr/bin/ruby
require 'mysql'
con = Mysql.new('localhost', 'root', 'root', 'rubytest')
rs = con.query('select * from people')
rs.each_hash { |h| puts h['name']}
con.close
从命令行运行时ruby test.rb
,我得到的字段很好。当从本地主机(http://localhost/cgi-bin/test.rb)点击 test.rb 时,我在错误日志中得到一个 500 和一个关于 mysql 丢失的唠叨 -
阿帕奇错误日志:
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] /Library/WebServer/CGI-Executables/test.rb:3:in `require': no such file to load -- mysql (LoadError)
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] \tfrom /Library/WebServer/CGI-Executables/test.rb:3
[Fri Aug 31 23:47:22 2012] [error] [client 127.0.0.1] Premature end of script headers: test.rb
我在 ~/.bashrc 中的导出路径:
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
export PATH="$PATH:/usr/local/mysql/bin"
export PS1="$ "
如果这有任何帮助,请运行gem env | grep 'RUBY EXECUTABLE'
RUBY EXECUTABLE: /Users/robertcox/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
任何帮助表示赞赏