You are not logged in.

#1 2015-06-21 22:15:19

Bailando
Member
From: Hungary
Registered: 2013-08-19
Posts: 133
Website

How to properly require any Ruby gem in an Apache CGI application?

My Ruby CGI scripts doesn't work when I require any gem. I would like to use the "peach" gem in my app, and it was installed by "gem install peach", however I installed it as root. My test app, called "gemtest":

#!/usr/bin/ruby

require "cgi"
require "peach"

cgi=CGI.new(:accept_charset => "UTF-8")

puts "Content type: text/plain; charset: 'UTF-8'"
puts
puts "It Works!"

It always throws an error in the apache error log:

/usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
cannot load such file -- peach
(
LoadError
)
\tfrom /usr/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
\tfrom /opt/lampp/cgi-bin/gemtest:6:in `<main>'
End of script output before headers: gemtest

I also tried to set up LOAD_PATH amd GEM_PATH environment variables in my Apache's httpd.conf file with directive "SetEnv", and I always restarted the Apache daemon:

SetEnv LOAD_PATH "/home/my_username/.gem/ruby/2.2.0/gems/"
SetEnv GEM_PATH "/home/my_username/.gem/ruby/2.2.0/gems/" 

But I had no success. How to require properly any Ruby gem when running simple CGI apps?

Offline

#2 2015-06-22 00:31:14

Bailando
Member
From: Hungary
Registered: 2013-08-19
Posts: 133
Website

Re: How to properly require any Ruby gem in an Apache CGI application?

Problem solved, I had to use this directive in httpd.conf:

 SetEnv GEM_HOME "/home/daemon/.gem/ruby/2.2.0"

And of course installing the gem as user "daemon".

Offline

Board footer

Powered by FluxBB