I am trying to get a ruby app running via Phusion_Passenger (6.0.15) and Apache (2.4.54). The app is OpenProject (v12) and the system is a Raspberry PI4, but I guess this does not matter for the problem at hand.
When loading the app via Passenger I have the problem that gems are incorrectly loaded from the "system" gem list and not the openproject app vendor/bundle folder
gems installed as given in Gemfile.lock via bundle install --deployment
manually confirmed that the gems are indeed all correctly available in ./vendor/bundle folder
Passenger loads and reports an error loading the app
Looking into the errors it shows that it is incorrect versions and / or missing gems due to the fact that apparently only gems from the system wide locations (more specifically: from the user space gems that are also around) are pulled, not from vendor/bundle
Passenger bundler/setup seems to be working somehow but something is wrong with the load paths apparently
looking at "activated_gems" from the log files (Passenger friendly error pages) it shows that it is all the wrong versions, i.e. not from vendor/bundle; if I remove a gem from the default, it then also disappears from the "activated_gems"
user and users rights seem to be correct; passenger reports the user ("openproject") under which the app should be running, vendor/bundle directories and sub-folders are owned by this user and accessible
Below are some more details from the error pages / log provided by passenger
Are there any ideas what could be wrong and causing passenger bundler to not pick up the gems from the vendor/bundle folder?
ruby_info
RUBY_VERSION = 3.1.2
RUBY_PLATFORM = aarch64-linux
RUBY_ENGINE = ruby
RubyGems version = 3.3.25
RubyGems paths = ["/home/openproject/openproject/vendor/bundle/ruby/3.1.0"]
Environment Variables
USER = openproject
TEXTDOMAIN = Linux-PAM
SHLVL = 0
HOME = /home/openproject
WSGI_ENV = development
PYTHONUNBUFFERED = 1
PASSENGER_USE_FEEDBACK_FD = true
APACHE_RUN_DIR = /var/run/apache2
APACHE_PID_FILE = /var/run/apache2/apache2.pid
LOGNAME = openproject
JOURNAL_STREAM = 8:19903
SERVER_SOFTWARE = Apache/2.4.54 (Debian) Phusion_Passenger/6.0.15
RACK_ENV = development
RBENV_SHELL = bash
PATH = /home/openproject/openproject/vendor/bundle/ruby/3.1.0/bin:/home/openproject/.nodenv/shims:/home/openproject/.nodenv/bin:/home/openproject/.rbenv/shims:/home/openproject/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
INVOCATION_ID = fcc115b63f334260aa3d8095470cde64
APACHE_LOCK_DIR = /var/lock/apache2
LANG = C
PASSENGER_SPAWN_WORK_DIR = /tmp/passenger.spawn.XXXXA4E1WH
SHELL = /bin/bash
IN_PASSENGER = 1
NODE_PATH = /home/openproject/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/passenger-6.0.15/src/nodejs_supportlib
APACHE_RUN_GROUP = www-data
APACHE_RUN_USER = www-data
APACHE_LOG_DIR = /var/log/apache2
RAILS_ENV = development
SECRET_KEY_BASE = 1f1b879d25c6e48581ea65067c808ac965bd7598eb0bdf2ba497865e32113cbf5e5a290b59bfab62e882c03eac3ff61efb4cbc954984c422c5770ee931d0c4d0
NODENV_SHELL = bash
PWD = /home/openproject/openproject
PASSENGER_APP_ENV = development
NODE_ENV = development
BUNDLER_ORIG_BUNDLE_BIN_PATH = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_BUNDLE_GEMFILE = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_BUNDLER_VERSION = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_GEM_HOME = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_GEM_PATH = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_MANPATH = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_PATH = /home/openproject/.nodenv/shims:/home/openproject/.nodenv/bin:/home/openproject/.rbenv/shims:/home/openproject/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
BUNDLER_ORIG_RB_USER_INSTALL = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_RUBYLIB = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
BUNDLER_ORIG_RUBYOPT = BUNDLER_ENVIRONMENT_PRESERVER_INTENTIONALLY_NIL
GEM_PATH =
GEM_HOME = /home/openproject/openproject/vendor/bundle/ruby/3.1.0
BUNDLE_BIN_PATH = /home/openproject/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.12/exe/bundle
BUNDLE_GEMFILE = /home/openproject/openproject/Gemfile
BUNDLER_VERSION = 2.3.12
RUBYOPT = -r/home/openproject/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.12/lib/bundler/setup
RUBYLIB = /home/openproject/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.12/lib
Ok, in the end I figured it out. Probably more of a workaround. Also according to the documentation I have read it should not have been necessary, but anyways.
Adding
SetEnv GEM_PATH /home/openproject/openproject/vendor/bundle/ruby/3.1.0
to /etc/apache2/sites-available/openproject.conf
Related
I am trying to deploy rails app through chef . code deployed successfully ,but bundle install throwing error for specific gems , When installed manually gem installs without any issues , as per the chef error i got to know that , to execute bundle install chef uses its embedded ruby version and path for the same , but system is installed with ruby 2.0 using rvm .Can we override the chef ruby path to system ruby path ? I am using following code to deploy ,
deploy_branch "master" do
repo repo_url
migrate false
action :deploy
branch 'master'
enable_submodules true
before_migrate do
current_release_directory = release_path
running_deploy_user = new_resource.user
bundler_depot = new_resource.shared_path + '/bundle'
excluded_groups = %w(development test)
script 'Bundling the gems' do
interpreter 'bash'
cwd current_release_directory
user running_deploy_user
code <<-EOS
bundle install --quiet --deployment --path #{bundler_depot} \
--without #{excluded_groups.join(' ')}
EOS
end
end
end
I have a VPS running Ubuntu 12.04. I've installed Nginx and Passenger on it by following these and these instructions, and as per the instructions, I've added to the http block of file /etc/nginx/nginx.conf the following lines:
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
and the following block (where I've replaced the actual domain name by www.example.com):
server {
listen 80;
server_name www.example.com;
root /srv/rails/myapp/public;
passenger_enabled on;
}
The Rails application lives in directory /srv/rails/myapp/, which is also a Git project directory. The directory and all its contents are owned by user rails. I've made the directory world-writeable, and, as user rails, run the following commands in it:
git pull
gem install bundler
bundle install
rake db:migrate
RAILS_ENV=production bundle exec rake assets:precompile
After this, running the application in development mode succeeds: when I command rails s, and open http://www.example.com:3000, the application works fine.
However, after doing the all the above, and commanding sudo service nginx restart, opening http://www.example.com yields a Passenger error screen, which says:
no such file to load -- bundler/setup (LoadError)
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:245:in `run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:348:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:243:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158
There's lots of debug output below that, and I'm not sure which of it is useful, but here's an excerpt:
Application root
/srv/rails/myapp
Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production
Ruby interpreter command
/usr/bin/ruby
User and groups
uid=1001(rails) gid=1002(rails) groups=1002(rails)
Environment variables
SHELL = /bin/bash
PASSENGER_DEBUG_DIR = /tmp/passenger.spawn-debug.XXXX2fPMPM
USER = rails
PWD = /srv/rails/myapp
SHLVL = 0
HOME = /home/rails
LOGNAME = rails
SERVER_SOFTWARE = nginx/1.4.6
IN_PASSENGER = 1
PYTHONUNBUFFERED = 1
NODE_PATH = /usr/share/passenger/node
RAILS_ENV = production
RACK_ENV = production
WSGI_ENV = production
NODE_ENV = production
PASSENGER_APP_ENV = production
SERVER_PROTOCOL = HTTP/1.1
SCGI = 1
DOCUMENT_ROOT = /srv/rails/myapp/public
QUERY_STRING =
SERVER_NAME = www.example.com
REMOTE_PORT = 49316
REMOTE_ADDR = [redacted]
SERVER_PORT = 80
REQUEST_METHOD = GET
SERVER_ADDR = [redacted]
REQUEST_URI = /
...
General Ruby interpreter information
RUBY_VERSION = 1.8.7
RUBY_PLATFORM = x86_64-linux
RUBY_ENGINE = nil
RubyGems version = 1.8.15
The application uses Ruby v2.0.0p353 while Passenger seems to use v1.8.7; I'm not sure if that has anything to do with this problem. (The Ruby used by the app lives in /home/rails/.rvm/rubies/ruby-2.0.0-p353/.)
I've searched for other problems where Passengers outputs this error, but nothing I've tried so far fixes the problem.
I don't really know if this will help, but try, in your projects folder:
which ruby # for example /home/rails/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
And this will output which ruby your bundle is using. Put that value, replacing this:
passenger_ruby /usr/bin/ruby;
to this
passenger_ruby /home/rails/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
end
edit:
this Linux command:
echo $MY_RUBY_HOME/bin/ruby
might be the easiest and most correct way to find your ruby binary.
After trying various things, I gave up on having nginx installed from Debian packages. I removed it, and also removed my rubies and RVM, then reinstalled everything, following these directions. The article advises how to install nginx using the passenger-install-nginx-module command that comes with the passenger gem. It checks all dependencies, and if it can proceed, downloads and compiles nginx. By default, it's installed in /opt/nginx/.
This did not work immediately. I also had to create an nginx startup script; instructions here. Furthermore, I had to edit the /opt/nginx/conf/nginx.conf file to add a reference to my application, and also had to comment out the location / block. After all this, and commanding sudo service nginx restart, the site is up.
my environment is as follows:
Ubuntu 10.04
Ruby 2.0.0
Rails 4.0
The deployed Rails application resides in /var/www/application. The deployment is handled by Capistrano, therefore, the directory structure is as follows:
root#lvps91-250-114-42:/var/www/application# ls -la
total 16
drwxrwxr-x 4 www-data www-data 4096 2013-11-14 12:53 .
drwxr-xr-x 6 www-data www-data 4096 2013-11-12 22:54 ..
lrwxrwxrwx 1 www-data www-data 39 2013-11-14 12:53 current -> /var/www/application/releases/20131114115156
drwxrwxr-x 11 www-data www-data 4096 2013-11-14 12:51 releases
drwxrwxr-x 8 www-data www-data 4096 2013-11-13 01:49 shared
The config/deploy.rb is configured to use a :local ruby (which has been installed into ../shared). The capistrano config:
require 'bundler/capistrano'
require 'rvm/capistrano'
#....
set :bundle_flags, "--deployment"
set :default_shell, '/bin/bash -l'
set :rvm_ruby_string, :local
#....
before 'deploy:setup', 'rvm:install_rvm'
before 'deploy:setup', 'rvm:install_ruby'
Maybe this plays a role because there is another rvm/ruby installation which is recognized when installing the Passenger. Passenger told me to configure the Apache 2 as follows:
LoadModule passenger_module /root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24/buildout/apache2/mod_passenger.so
PassengerRoot /root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24
PassengerDefaultRuby /root/.rvm/wrappers/ruby-2.0.0-p247/ruby
But it complained about my .rvm installation (which resides in root :-() and that I will need to change the permissions (but I didn't change them):
It is recommended that you relax permissions as follows:
sudo chmod o+x "/root"
Press Ctrl-C to return to the shell. (Recommended)
After relaxing permissions, re-run this installer.
-OR-
Press Enter to continue anyway.
The corresponding sites-enabled/application configuration:
<VirtualHost *:80>
ServerName subdomain.domain.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/application/current/public
<Directory /var/www/application/current/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
When I started the application, I got the following error in my browser:
Cannot execute "/root/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.24/buildout/agents/SpawnPreparer": Permission denied (errno=13)
After:
sudo chmod o+x "/root"
Everything is working.
What is your advice to fix it? Should I re-install .rvm and passenger? Can I reconfigure the Apache configuration so that Apache will access all those executables which reside in /var/www/application?
Thank you in advance!!
jepetko
If you have used the rvm installation method for a single user, have you considered setting the ownership of the files for the ruby application to be the same as the owner of rvm?
For myself, I have ran into this problem before and here is what I have done:
Create new user for managing rvm
Add the new user to be able to sudo to root
Login as the new user and install rvm as a single user
Install passenger gem
Run passenger installation for module with rvmsudo
Set the ownership of the ruby application to be the same as the new user account for rvm management
Sometimes I have had to add the following to my apache conf:
SetEnv LD_LIBRARY_PATH /home/rvmuser/.rvm/default/lib
SetEnv GEM_PATH /home/rvmuser/.rvm/gems/ruby-1.9.3-p484:/home/rvmuser/.rvm/gems/ruby-1.9.3-p484#global
Hope this helps!
i have same problem with you before and this is how i solve it:
try use set config PassengerUser https://www.phusionpassenger.com/library/config/apache/reference/#passengeruser . Set it with user that you use when install rvm. Because you put the rails app on /var/www/ which is that is owned with apache/www-data you need specify user that owned the rvm.
So, based on you example, just add: PassengerUser deploy after or before DocumentRoot config on your apache config.
Don't forget to restart the apache. Good luck.
Capistrano raises the error "ERROR: Gem bundler is not installed, run gem install bundler first."
But when I clone the project to /tmp/project of the targe server bundle runs (as root) smoothly.
The server is a Ubuntu 12.04.2 LTS, ruby was installed via rvm.
I added "source /usr/local/rvm/scripts/rvm" to the /root/.bashrc but it did not solve the problem.
require "bundler/capistrano"
set :application, 'myproject'
set :repository, "git#myproject.git"
set :branch, 'staging'
set :user, 'root'
set :domain, "mydomain"
set :deploy_to, "/var/webapps/#{application}"
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
role :db, domain
default_run_options[:pty] = true
# [and then the tasks]
TIA.
EDIT
This very same deploy script worked in another server, with ruby installed in the same way. The only difference I remember is that that server was a CentOS.
Also tried rvm wrapper rvm current bundle bundle as suggested here
Edit 2
I compared the env command via ssh and via capistrano. The following env variables were missing when env was issued by capistrano:
__array_start=0
_first=0
_second=1
escape_flag=1
GEM_HOME=/usr/local/rvm/gems/ruby-1.9.3-p392
GEM_PATH=/usr/local/rvm/gems/ruby-1.9.3-p392:/usr/local/rvm/gems/ruby-1.9.3-p392#global
IRBRC=/usr/local/rvm/rubies/ruby-1.9.3-p392/.irbrc
LC_ADDRESS=pt_BR.UTF-8
LC_IDENTIFICATION=pt_BR.UTF-8
LC_MEASUREMENT=pt_BR.UTF-8
LC_MONETARY=pt_BR.UTF-8
LC_NAME=pt_BR.UTF-8
LC_NUMERIC=pt_BR.UTF-8
LC_PAPER=pt_BR.UTF-8
LC_TELEPHONE=pt_BR.UTF-8
LC_TIME=pt_BR.UTF-8
LESSCLOSE=/usr/bin/lesspipe %s %s
LESSOPEN=| /usr/bin/lesspipe %s
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-1.9.3-p392
RUBY_VERSION=ruby-1.9.3-p392
rvm_bin_path=/usr/local/rvm/bin
rvm_debug_clr=
rvm_error_clr=
rvm_notify_clr=
rvm_path=/usr/local/rvm
rvm_prefix=/usr/local
rvm_reset_clr=
rvm_version=1.19.5 (stable)
rvm_warn_clr=
The following env vars were different:
_=/usr/bin/env # ssh
_=/bin/sh # capistrano
LANG=en_US.UTF-8 # ssh
LANG=C # capistrano
LANGUAGE=en # ssh
LANGUAGE=C # capistrano
# ssh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/rvm/bin
# capistrano
PATH=/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392#global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
I had a similar problem with one of my setups, though I use rbenv to manage ruby versions. The issue was that bundler was not installed on the Ruby version my project was pointing to.
I did a quick check online and you have a few options:
run rvm gemset use global && gem install bundler (installs to
global version)
edit your /.bashrc ... something along those lines
([[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm")
Running gem env may show you that you are forcing a path, and you would then need to remove the entry from ~/.gemrc or /etc/gemrc
My 2-cents
Rails 3.1 has changed the way it handles the asset pipeline and it is causing issues when deploying to production.
I am using Apache and Passenger, which seem to work fine.
My production is setup like this (for now).
# congif/environments/production.rb
config.cache_classes = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = false
config.assets.digest = true
config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
I run rake assets:precompile on Ubuntu and start server. And... nothing. None of my images load.
The legendary 'I can't find an image at this URL' box.
I run rake assets:precompile on CentOS and start server. And... permission errors.
*Error Compiling CSS Asset*
Errno::EACCESS: Permission Denied - [app path]/tmp/cache/assets/E95
[path to RVM Ruby]/fileutils.rb:243:in 'mkdir'
I can't get it to budge. Any help is greatly appreciated. Thank you!
UPDATE
This solution has worked every time for me:
First Clean out your Assets
rm -rf public/assets
and
rake assets:clean RAILS_ENV=production
Second, in #production.rb change
config.assets.compile = false
to
config.assets.compile = true
Third, run to precompile your assets
rake assets:precompile RAILS_ENV=production
Fourth, in #production.rb change
config.assets.compile = true
back to
config.assets.compile = false
Fifth, restart your server by running:
touch tmp/restart.txt
Sixth, un-restrict permissions on your newly created assets by running this command
chmod -R 777 public/assets
Seventh, celebrate!!
That's a simple permission problem. Give the server/daemon the right to create files in [app_path]/tmp recursively.
Assuming your server process runs with the www-data user you do this with:
cd APP_PATH
chmod -R u+w tmp
and if the directory does not belong to the user you have to change the ownership:
chown -R www-data tmp
Try creating public/assets via sudo or try performing rvmsudo rake assets:precompile - essentially, it's not able to create the directory on your server — hence the error.
On Windows 8:
Remove references to stylesheets
Restart production
Go to an affected page using browser
Add stylesheet references back
Restart production
Worked for me!
Your updated solution did not work for me.
I am on rails 4.2 and css and js works only when I set
config.serve_static_files = true (which is not recommended but it is the only way I can make things work here).