KGolbang
KGolbang

Reputation: 445

Using Passenger with Rails and Apache 2 / SpawnPreparer Permission denied

my environment is as follows:

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

Upvotes: 3

Views: 4706

Answers (2)

Mada Aryakusumah
Mada Aryakusumah

Reputation: 611

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.

Upvotes: 0

aaron
aaron

Reputation: 86

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!

Upvotes: 1

Related Questions