I am having a ruby gem path problem starting passenger on apache.
Environment:
ubuntu-20
passenger-6.0.14
ruby-3.0.4
Ruby was installed system-wide using ruby-install, and is located at
/opt/rubies/ruby-3.0.4
chruby is being used to set the ruby environment.
ruby apps and gems are (hopefully) installed on a per-user and per-app basis. In this case, redmine is the only app.
When I visit the newly-created redmine site, passenger fails to start rails because of a gem path problem:
Raw Bundler exception:
Bundler was unable to find one of the gems defined in the Gemfile
Bundler tried to load the gems from #<struct Bundler::Settings::Path explicit_path=nil, system_path=false>
Could not find rails-6.1.4.7, rouge-3.28.0, ...
The gems are in fact, present:
$ cd ~
$ find . | grep rails-6.1.4
./.gem/ruby/3.0.4/specifications/rails-6.1.4.7.gemspec
./.gem/ruby/3.0.4/cache/rails-6.1.4.7.gem
./.gem/ruby/3.0.4/gems/rails-6.1.4.7
./.gem/ruby/3.0.4/gems/rails-6.1.4.7/README.md
The apache ssl startup for the virtual host looks like:
<IfModule mod_passenger.c>
PassengerRoot /home/test_user/.gem/ruby/3.0.4/gems/passenger-6.0.14
PassengerDefaultRuby /opt/rubies/ruby-3.0.4/bin/ruby
</IfModule>
...
Include rubies/test_user.include
and rubies/test_user.include has:
<Directory /var/www/html/issues-test>
PassengerAppRoot /home/test_user/redmine_test
PassengerAppEnv redmine_test
PassengerAppGroupName redmine_test
RailsBaseURI /issues-test
PassengerUser test_user
PassengerGroup test_user
PassengerFriendlyErrorPages on
</Directory>
The gem environment for the user where redmine is installed:
- RUBYGEMS VERSION: 3.2.33
- RUBY VERSION: 3.0.4 (2022-04-12 patchlevel 208) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.4
- USER INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.0
- RUBY EXECUTABLE: /opt/rubies/ruby-3.0.4/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /home/test_user/.gem/ruby/3.0.4/bin
- SPEC CACHE DIRECTORY: /home/test_user/.local/share/gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /opt/rubies/ruby-3.0.4/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/test_user/.gem/ruby/3.0.4
- /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0
- SHELL PATH:
- /home/test_user/.gem/ruby/3.0.4/bin
- /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/bin
- /opt/rubies/ruby-3.0.4/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /snap/bin
Note that the shell PATH does not include the
/home/test_user/.gem/ruby/3.0.4/gems/
path; and the test_user.include shows no path to the gems for passenger.
I'm not clear on how ruby/passenger establishes the path for gems.
The passenger install was done from the user environment.
Note: I'm also unclear as to why the INSTALLATION DIRECTORY shows
/home/test_user/.gem/ruby/3.0.4
but the USER INSTALLATION DIRECTORY shows
/home/test_user/.gem/ruby/3.0.0.
(At some point I may have done ruby-install 3.0 and it installed 3.0.4). There is, however, no directory ~/.gem/ruby/3.0.0
There were a couple of issues here. Thanks #Casper for some hints.
Passenger must be installed system-wide, i.e., as root.
It was installed as the redmine user, so had to be de-installed.
Checking the passenger uninstall page for apache, it says
"Remove the passenger files" and then details how to do that, assuming passenger was installed any way except from source.
Unfortunately, I installed from source, as the regular repositories are way out of date. Uninstalling from source is non-trivial, as the passenger files are mixed in with the other application files and there is no easy way to find them all and differentiate. I ended up deleting the entire ruby / redmine environment for the user and starting over.
To install passenger as root, in a ruby-install/chruby environment:
sudo -i
cd /opt/rubies
source /usr/local/share/chruby/chruby.sh
chruby 3.0.4
gem install passenger
passenger-install-apache2-module
exit
Once passenger was re-installed globally, attempting to set up redmine for a specific user still failed with the same error -- Bundler can't find any gems. I read several places that one should not have to set the GEM_PATH explicitly, as Passenger/Ruby/Bundler are supposed to be able to automatically find the gems they need if they are in a conventional place, but apparently not. My assumption was that since the passenger definition for the redmine app specified the user environment properly, they should be found. (It's not clear to me if this problem is specific to Passenger, an Apache2 installation, or Ruby/Bundler)
The problem may be because I am using ruby-install and not rvm; passenger's docs seem to assume rvm is used as the installer.
In any case, I had to explicitly set GEM_PATH in the apache2 configuration.
The path is the one shown if "gem env GEM_PATH" is given from the user account.
So for this case, in (file rubies/test_user.include above), add the line:
SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/
The complete apache2 config fragment looks like:
<Directory /var/www/html/issues-test>
PassengerAppRoot /home/test_user/redmine_test
PassengerAppEnv redmine_test
PassengerAppGroupName redmine_test
RailsBaseURI /issues-test
PassengerUser test_user
PassengerGroup test_user
PassengerFriendlyErrorPages on
SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/
</Directory>
Related
I have a ROR app (version 6.1.4.1) with Ruby 2.7.4 on a Raspberry Pi 4 with 4 GB RAM and a 32 GB SD card. I installed Passenger 6.0.12 using the tarball installation and am running it with nginx. passenger start in the app directory works successfully, but when I try running it as with nginx (/opt/nginx/sbin/nginx) on port 80, I get the above error when visiting the site.
I'm accessing the app via IP address, which is configured in the nginx.conf and the app is installed in /home/pi/src/bogie_can. There is a .bundle directory with a config file in the app directory, and that's where the gems are installed. I'm running the app in "development" mode, which is configured in the server section of the nginx.conf file using passenger_app_env.
The specific error is that the app cannot find racc-1.5.2. The Bundler info is #<struct Bundler::Settings::Path explicit_path="/home/pi/src/bogie_can/.bundle", system_path=false, default_install_uses_path=false>.. So, we note that the .bundle path is correct and in the .bundle/ruby/2.7.0/gems/ directory, racc-1.5.2 is indeed installed and owned by the user "pi".
I've cleared out old bundle installations and tried switching the app user from pi to root (which was nobody) and back. Also, I'm using rbenv, so I also ran rbenv rehash after the fresh bundle install. I've also carefully reviewed the "Detailed diagnostics" from the Passenger error page (which is super helpful!) and do not see anything that is obviously wrong.
Using the Passenger error page as a guide, it seems that:
The gems are indeed installed as needed
The user, either root or pi, have permissions to access the gems
pi is a reasonable user to run the app
The passenger_root and passenger_ruby are coming from the passenger-config about subcommands and are verified as well.
At this point, there must be some configuration I've overlooked or gotten wrong and I would greatly appreciate some questions and pointers.
I found the root cause of the problem.
I had set passenger_ruby to the result of passenger-command about ruby-command, which gave me:
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/bin/ruby2.7
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /usr/bin/ruby2.7
To use in Nginx : passenger_ruby /usr/bin/ruby2.7
To use with Standalone: /usr/bin/ruby2.7 /usr/src/passenger-6.0.12/bin/passenger start
The following Ruby interpreter was found first in $PATH:
Command: /home/pi/.rbenv/shims/ruby
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /home/pi/.rbenv/shims/ruby
To use in Nginx : passenger_ruby /home/pi/.rbenv/shims/ruby
To use with Standalone: /home/pi/.rbenv/shims/ruby /usr/src/passenger-6.0.12/bin/passenger start
I was using /usr/bin/ruby2.7 and having the problem with racc not being found. I switched it to use the rbenv shim and Passenger was able to correctly find all the gems in the [APP_ROOT]/.bundle/ directory
I also cleared out the default nginx installation, which was still trying to be started with nginx.service and then added my own /etc/init.d/nginx script and added it to the init.d database so that it now starts with the OS.
I am running Apache on my Raspberry Pi (Raspbian) and struggling to get Passenger working properly with my site. When I go to visit my site (which is set up as a VirtualHost), I get the error: "cannot load such file -- bundler". The first line of the backtrace is
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb
To install Passenger, I followed the instructions here: http://www.modrails.com/documentation/Users%20guide%20Apache.html#install_on_debian_ubuntu.
In particular, I ran the command
sudo apt-get install libapache2-mod-passenger
This link says, "The Apache package provides configuration snippets for you, so you don’t need to modify any Apache configuration to get it to load Phusion Passenger". The way the installation went on my machine was that it automatically added and enabled the passenger module through the files "passenger.conf" and "passenger.load":
passenger.conf:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>
passenger.load:
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
Running "gem env" gives me the following output:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.7
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [armv6l-linux-eabihf]
- INSTALLATION DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p247
- RUBY EXECUTABLE: /home/user/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p247/bin
- RUBYGEMS PLATFORMS:
- ruby
- armv6l-linux
- GEM PATHS:
- /home/user/.rvm/gems/ruby-2.0.0-p247
- /home/user/.rvm/gems/ruby-2.0.0-p247#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
I tried looking all over for a mod_passenger.so file elsewhere in the file system with no luck. I am reluctant to simply reinstall rails or passenger because I am unsure what the implications will be for the modules and configuration. Any advice is appreciated, thanks!
Maybe you didn't configure your app to use Ruby 2.0.0? If you don't do that explicitly, it will use the default Ruby, which is /usr/bin/ruby. This section from the manual tells you how to specify a different Ruby: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerRuby
Note that multiple Ruby supports requires Phusion Passenger >= 4.0.0.
The problem ended up being that I needed to set the environment variable for the GEM_PATH within a .htaccess file!
I'd like my rails server to start automatically after every reboot, so I added the following to my .bashrc file
rvm use 1.9.2
cd /home/user/myapp
rails server
With that, the server never starts automatically after a reboot, and I have to start it manually.
Also, when I login to start the server, I see the following message
Using /usr/local/rvm/gems/ruby-1.9.2-p290
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby: symbol lookup error: /usr/local/rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.4/lib/sqlite3/sqlite3_native.so: undefined symbol: sqlite3_initialize
As a consequence, I need to install sqlite3 after every reboot using "gem install sqlite3" after I make myself superuser, and only then I can start the rails server without issues.
$ cat /etc/*-release
CentOS release 5.8 (Final)
$ rails -v
Rails 3.1.1
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]
Anyone can please help me overcome this issue? Thanks
Install Apache and Passenger
They will take care of starting your App with the server in a safer and more systematic way and what is now more or less a standard.
I had the same issue with Rails 4, Ruby 2.1 on CentOS 6. If you're not familiar with bash scripts and the rc, profiles system - it's much faster and easier to setup passenger.
Also, there are other reasons why you would go for passenger, including security and performance ( www.phusionpassenger.com )
Here is a quick how-to of what it took me to introduce the gem.
Install Apache (html daemon) and dependency packages (if you don't have them already):
yum install httpd curl-devel httpd-devel
Get Apache to start on boot:
chkconfig httpd on
Install Phusion Passenger and dependency packages:
gem install passenger
yum install curl-devel httpd-devel
Compile the environment:
passenger-install-apache2-module
Edit the Apache config file in etc/httpd/conf/httpd.conf
Uncomment the line containing NameVirtualHost *:80 towards the end
Paste the output from point 4) anywhere at the end of the file, eg:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.1.1/wrappers/ruby
<VirtualHost *:80>
ServerName 1.2.3.4 # www.whatever.com
DocumentRoot /var/www/rails/public # the path to your rails app
<Directory /var/www/rails/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Took me 30 minutes in total, including several trial-errors with the httpd.conf to get everything right.
Note that installation requires at least 1 GB RAM on your machine.
I've got a server that predominantly runs Ruby 1.8.7, but now I have a Rails 3.2 app that needs 1.9.3. I've installed Passenger 4 as it supports the ability to run multiple Rubies on a per-virtual server basis.
However, it appears that while you can assign a particular Ruby, the application doesn't have access to that Ruby's gemset. So I have my virtual server configured with the 1.9.3 Ruby, as confirmed on the error page my application now gives:
Ruby interpreter command
/home/aaron/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
But the GEM_HOME parameter tells a different story:
GEM_HOME = /home/aaron/.rvm/gems/ruby-1.8.7-p352
Looking through the configuration directives for Passenger 4, I see no way to specify a different gemset. Am I missing something, or is this thing just not ready for prime time?
From your gemset dir run:
$ passenger-config --ruby-command
It will tell you ruby path for Apache and Nginx.
Command: /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
Version: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
To use in Apache: PassengerRuby /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
To use in Nginx : passenger_ruby /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
Nginx: For Passenger 4 you can specify multiple ruby versions. So for specific server config:
your_site.conf:
server {
listen 80;
root /home/aaron/web/public;
passenger_enabled on;
passenger_ruby /home/aaron/.rvm/wrappers/ruby-2.0.0-p247#your_gemset/ruby;
}
nginx.conf: (this works for new passenger 4.0.17)
http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
}
Just run from your gemset dir this:
$ passenger-status
It will check whether passenger_native_support.so is available. Depending on your RVM installation, you might need to run it with rvmsudo
$ rvmsudo passenger-status
For Debian/Ubuntu there are now binary packages of nginx and passenger available which makes the installation much easier.
As Tombart pointed out: If you use the precompiled Passenger modules (in my case for for Apache2) you end up with a system up and running.
However, if using RVM I stumbled upon the fact that you need to use the "wrapper directory" to select the correct RVM ruby version and gemet like so in your Apache vhost config:
PassengerRuby /home/of_your_ruby_user/.rvm/wrappers/ruby-x.y.z-p123#gemset/ruby
This way Passenger knows how to find the correct gemset relative to this directory (../../gems/ruby-x.y.z-p123#gemset/gems). Otherwise Passenger would use the "standard ruby gemset" which is odd if you want to run multiple apps with the same ruby version. I can only guess that this is similar for Nginx.
I have managed to install ruby 1.9.2 with rvm and rails,, but am having some trouble getting passenger installed. I have the source files in my /opt directory. When I run sudo ./passenger-install-nginx-module in the passenger bin directory I get this error: /usr/bin/env: ruby: No such file or directory
rvm info:
Ruby Path "/home/me/.rvm/rubies/ruby-1.9.2-p180/bin/ruby"
Use rvmsudo instead of sudo to run the passenger install command. Also, you may need to specify the full path to that command. On my server it's something like this:
rvmsudo /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11/bin/passenger-install-apache2-module
You should be able to generate an RVM wrapper script (shell script to select RVM ruby):
rvm wrapper default_192
...and then set PassengerRuby in your Passenger config (tell Passenger which ruby to use):
PassengerRuby /home/your_user/.rvm/bin/default_192
if ever you find yourself wondering why your vagrant box has suddenly stopped loading your website, and you have the passenger gem installed, there's a big possibility that it has automatically upgraded the gem and needs you to make a few changes to the apache module for it. This is just one issue I have come across.
So in light of sharing the knowledge just open the following file for editing on the command using your preferred editor if you're running apache.
/etc/apache2/conf.d/passenger
and replace the three lines with the following:
. LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.10/buildout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.10
PassengerDefaultRuby /usr/bin/ruby1.9.1
we're basically replacing the version number the module should use.