Redmine and backlog no such file to load -- phusion_passenger/utils (LoadError) - passenger

I tried to install redmine with backlog plugin. I followed this tutorial: https://github.com/backlogs/redmine_backlogs/wiki/Installation-of-Backlogs-in-Redmine-2.0
And now I have apache error:
/usr/lib/phusion_passenger/passenger-spawn-server:53:in `require': no such file to load -- phusion_passenger/utils (LoadError)
from /usr/lib/phusion_passenger/passenger-spawn-server:53:in `<main>'
[ pid=4064 file=ext/apache2/Hooks.cpp:725 time=2012-09-16 23:23:45.726 ]:
Unexpected error in mod_passenger: Cannot spawn application '/var/www/redmine': The spawn server has exited unexpectedly.
Backtrace:
in 'virtual boost::shared_ptr<Passenger::Application::Session> Passenger::ApplicationPoolServer::Client::get(const Passenger::PoolOptions&)' (ApplicationPoolServer.h:471)
in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:521)
This is my virtual host config:
<VirtualHost *:80>
ServerName redmine.my.domain
DocumentRoot "/var/www/redmine/public"
<Directory "/var/www/redmine/public/">
RailsBaseURI /redmine
PassengerResolveSymlinksInDocumentRoot on
</Directory>
</VirtualHost>
My /etc/apache2/mods-available/passenger.conf
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
PassengerDefaultUser www-data
</IfModule>
More:
/usr/bin/ruby -> /etc/alternatives/ruby
/etc/alternatives/ruby -> /usr/bin/ruby1.9.1
ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
Any idea?

Did you look at the hints from this question: Rails application doesn't work with apache2 and passenger ? (it looks like the same type of error). One person had several versions of Ruby installed which was causing problems.
Hope it'll help.

Related

How to run Ruby gems as apache

On an AWS EC2 amazon linux instance I am getting the error:
/usr/local/share/ruby/site_ruby/2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- syck (LoadError)
from /usr/local/share/ruby/site_ruby/2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from beats-1.3.0/bin/beats:8:in `<main>'
when trying to execute a ruby bin as apache. I have set the permissions of html to 777, and I have copied over the installed gems from /home/ec2-user/.gem/ruby/2.0/gems to /usr/local/share/ruby.
I am aware that this is an issue normally solved with yum install ruby-devel and yum groupinstall development.
An interesting note, is that when I changed the user and group in httpd.conf to ec2-user/ec2-user, I got the same issue. It seems it is not the apache user, but I am stumped.

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 trows 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 gem when running simple CGI apps?
The problem is that the user who is trying to load the gem, most probably doesn't have access to the gem installed for your username
Check the username that loads the apache service in your apache configuration, most probably its the nobody user, and install the gem for that user
sudo su - nobody
gem install peach
If you don't want to deal with different gems for different users, you can always use bundler

Ruby Require behaviour differing when used with CGI vs command line

I have a very basic CGI script that's meant to output a bunch of information about the Ruby environment. Here's the code:
#!/usr/bin/env ruby
begin
puts <<-EOS
Content-type: text/html
<html>
<body>
EOS
puts "<p>$LOAD_PATH:</p>"
puts "<ul>"
$LOAD_PATH.each {|val| puts "<li>#{val}</li>"}
puts "</ul>"
require 'awesome_print'
puts "<p>RUBY_VERSION: #{RUBY_VERSION}</p>"
puts "<p>$SAFE: #{$SAFE}</p>"
puts "<p>$LOADED_FEATURES:</p>"
puts "<ul>"
$LOADED_FEATURES.each {|key,val| puts "<li>#{key} = #{val}</li>"}
puts "</ul>"
puts "<p>ENV:</p>"
puts "<ul>"
ENV.each {|key,val| puts "<li>#{key} = #{val}</li>"}
puts "</ul>"
rescue Exception => e
puts "<p>EXCEPTION. #{e.message}<br/>#{e.backtrace.join('<br/>')}</p>"
ensure
puts "</body></html>"
end
When I run this code from the browser via CGI, through apache2 on localhost, I get:
EXCEPTION. cannot load such file -- awesome_print
However, when I run from the CLI, it prints the info like it's supposed to.
I've compared the output of $LOAD_PATH, and they're identical in both cases, CGI vs CLI.
After some research, I figure the main difference between the CGI and CLI is the user running the service (e.g. www-data for the CGI, for the CLI), and as a result, the ENV available in each case differs. In the CLI case, I have the ENV that is augmented by RVM, providing variables like GEM_PATH and GEM_HOME. As such, I had to change the Apache envvars file to include the RVM modifications to $PATH, so that #!/usr/bin/env ruby would return the correct version of Ruby (2.1.3 installed with RVM as opposed to 1.8.7 system Ruby).
Other things I've tried:
sudo chmod +r -R /home/<user>/.rvm/rubies/ruby-2.1.3 : cannot load such file -- awesome_print (CGI only)
sudo chmod 777 -R /home/<user>/.rvm/rubies/ruby-2.1.3: cannot load such file -- awesome_print (CGI only)
ruby <myscript>.rb before running either source ~/.rvm/scripts/rvm or rvm use 2.1 : cannot load such file -- awesome_print (CLI)
IRB requireawesome_printreturnstrue` in .rvm-enabled CLI
IRB $LOAD_PATH after rvm use 2.1 returns:
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby/2.1.0",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby/2.1.0/x86_64-linux",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/vendor_ruby/2.1.0",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/vendor_ruby/2.1.0/x86_64-linux",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/vendor_ruby",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0",
"/home/user/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/x86_64-linux"
Note: the above output is the same $LOAD_PATH as given as output from both the CGI and CLI
gem which awesome_print gives /home/romistrub/.rvm/gems/ruby-2.1.3/gems/awesome_print-1.2.0/lib/awesome_print.rb
$LOAD_PATH << '/home/romistrub/.rvm/gems/ruby-2.1.3/gems/awesome_print-1.2.0/lib/' fixes the require issue for CGI, but is an ugly fix, as it does not work with gems that have their own dependencies without specifying the paths for all dependencies. E.g., the same $LOAD_PATH << using the lib portion of gem which faye/websocket will allow require 'faye/websocket' to load the core gem, but not its dependencies, e.g. eventmachine.
Given all of this (potentially superfluous) information, how do these two runtime environments (CGI vs CLI) result in differing require behaviour? Can someone direct me to a resource that goes into detail about the behaviour of require?
Thanks in advance.
So apparently rubygems overrides require, and as such require is actually looking for the awesome_print gem using the ENV['GEM_PATH'] environment variable, and not using $LOAD_PATH.
see rubygems / lib / rubygems / core_ext / kernel_require.rb
Because the GEM_PATH environment variable was set in bash by RVM through rvm use 2.1, and GEM_PATH was not set in the Apache environment (causing the inconsistent behaviour), I had to add the GEM_PATH that was found via the echo $GEM_PATH command in the CLI after RVM was loaded to the Apache environment using a SetEnv directive in the Apache configuration file.
My particular situation looked like this:
$> echo $GEM_PATH
/home/user/.rvm/gems/ruby-2.1.3:/home/user/.rvm/gems/ruby-2.1.3#global
then add SetEnv line to /etc/apache2/sites-available/default, e.g.:
<Directory /var/www/board/demo>
Options +ExecCGI
AddHandler cgi-script .rb
Allow from all
Options -MultiViews
SetEnv GEM_PATH /home/user/.rvm/gems/ruby-2.1.3:/home/user/.rvm/gems/ruby-2.1.3#global
</Directory>

VPS apache config - Invalid command 'PassengerDefaultRuby' after adding latest passenger gem

used to have this list of rubies in my vps:
ruby-1.9.2-p320 [ i686 ]
=* ruby-1.9.3-p194 [ i686 ]
ruby-1.9.3-p374 [ i686 ]
ruby-1.9.3-p392 [ i686 ]
today I installed a new app on this vps on ruby 2.0, so I added 2.0 to rvm:
ruby-1.9.2-p320 [ i686 ]
ruby-1.9.3-p194 [ i686 ]
ruby-1.9.3-p374 [ i686 ]
ruby-1.9.3-p392 [ i686 ]
=* ruby-2.0.0-p247 [ i686 ]
installed passenger and passenger-apache-module, instructions says to add these lines:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
to /etc/apache2/apache2.conf and restart apache, after restart I got this error:
Syntax error on line 242 of /etc/apache2/apache2.conf:
Invalid command 'PassengerDefaultRuby', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
and one more problem, when I open my app at http://nccm.md I got:
Could not find rake-10.1.0 in any of the sources (Bundler::GemNotFound)
from gem list command I can see this gem is installed in ruby 2.0 environment, but the app looks for it in usr/local/rvm/gems/ruby-1.9.3-p194#global. Why is that? Thank you for any help.
Got it!
you need to have a default ruby assigned at root level, the other ones you'll set in sites-enabled configuration files. For example, in my apache2.conf file:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.19
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p247/ruby
then in /etc/apache2/sites-enabled/mysite that fires up the app that should work in ruby-1.9.3 I'll add PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby:
<VirtualHost xxx.xx.xx.xx:80>
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
ServerName mysite.md
DocumentRoot /home/apps/myapp/public
<Directory /home/apps/myapp>
AllowOverride None
Options -MultiViews
</Directory>
</VirtualHost>
for the app that works with ruby-2.0 no need to add PassengerRuby option as ruby-2.0 is the default one now.
Also if you have other rvm passenger modules loaded in apache2.config file, like in my case I had:
# LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.18/ext/apache2/mod_passenger.so
# PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.18
# PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p194/ruby
you'll need to remove them or comment them as I did, as you'll load the ruby version in /etc/apache2/sites-enabled/mysite config file.
note!
This will only work on passenger > 4.0.0. I have tested this on
passenger-3.0.8 and it does not work. Note that PassengerDefaultRuby
was introduced in passenger version 4.0.0, see
modrails.com/documentation/….

Phusion Passenger: Trouble on deploying an application on the local machine

I am using Mac OS Snow Leopard, Apache Server, Phusion Passenger and RVM and I am trying to deploy on my local machine a RoR application.
In my ~.etc/apache/httpd.conf file I have:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mysite.com
DocumentRoot /Users/MyUserName/Sites/mysite.com/public
<Directory /Users/MyUserName/Sites/mysite.com/public>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I browse the mysite.com address I get the following Phusion Passenger' error:
Error message:
no such file to load -- bundler
Exception class:
LoadError
Application root:
/Users/MyUserName/Sites/mysite.com
Backtrace:
# File Line Location
0 /Users/MyUserName/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 36 in `require'
1 /Users/MyUserName/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 36 in `require'
...
How can I solve that?
Console outputs:
$ /usr/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin10.0]
$ echo $PATH
/Users/MyUserName/.rvm/gems/ruby-1.9.2-p290/bin:/Users/MyUserName/.rvm/gems/ruby-1.9.2-p290#global/bin:/Users/MyUserName/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/MyUserName/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
$ which ruby gem irb rake
/Users/MyUserName/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/MyUserName/.rvm/rubies/ruby-1.9.2-p290/bin/gem
/Users/MyUserName/.rvm/rubies/ruby-1.9.2-p290/bin/irb
/Users/MyUserName/.rvm/gems/ruby-1.9.2-p290/bin/rake
$ irb
1.9.2-p290 :001 > require "bundler"
=> true
I think you might have a mismatch in what ruby versions are used.
Apache/passenger is probably set up to use your system ruby (1.8.7-p249), and not the ruby version you are obviously using with rvm, and I guess the reason you get the message that passenger cannot find bundler is because you haven't installed bundler using your system ruby.
You can fix this either by installing bundler in the system ruby version, or by telling passenger to use whatever ruby version you have installed via rvm.

Resources