Search code examples
ruby-on-railsrubysymfonyubunturbenv

rbenv Permission denied with Assetic on Ubuntu


I struggled for hours trying to have Assetic with Sass and Compass working on my production server.

The error is:

sh: 1: /root/.rbenv/shims/ruby: Permission denied

This is because my rbenv instalation is under the /root directory so Assetic doesn't have the permision to use it.

I've checked similar issues:

but they didn't help.

I'm using Apache so I guess the default user is "www-data".

As explained in one of the above questions, I tried to grant www-data the permission in /root but either this didn't work or I did it wrong.

sudo chown -R www-data ~/.rbenv

This is the complete error:

[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
    [message] An error occurred while running:
    '/root/.rbenv/shims/ruby' '/usr/local/bin/compass' 'compile' '/var/www/myapp/app/cache/dev' '--boring' '--images-dir' '/var/www/myapp/app/../web/uploads/img' '--config' '/var/www/myapp/app/cache/dev/assetic_compassu3IAzJ' '--sass-dir' '' '--css-dir' '' '/var/www/formation-hero/app/cache/dev/assetic_compassPbwM3H.scss'

    Error Output:
    sh: 1: /root/.rbenv/shims/ruby: Permission denied

I'm using Apache on Ubuntu 14.04

#  which ruby
/root/.rbenv/shims/ruby

# which compass
/usr/local/bin/compass

# which rbenv
/root/.rbenv/bin/rbenv

# rbenv -v
rbenv 1.0.0-14-gc388331

Symfony 2.7 is installed under /var/www/myapp/

What should I do to either give right to Apache to use the /root repository or, maybe better, how do I install rbenv for my Symfony2 project?

Everything is working fine on my localhost with OS X.


Solution

  • I do not have experience with the said components but assuming that the user who is executing the file is www-data it might be an issue with the permissions of the /root/.rbend/shims/ruby file.

    Run the command sudo chmod o+x /root/.rbenv/shims/ruby wich will give execute permissions to the owner of the file, presumably www-data since you ran the chown command.

    If it still doesn't work run the command ls -l /root/.rbenv/shims/ruby, the 4th character of the first column should be x, indicating the owner has execution permissions.

    For more info on linux file permissions check "Understanding and Using File Permissions".