Rails Errno::EACCES Permission Denied
Asked Answered
D

10

31

Rails 3.1 Passenger on Apache Development environment When I go to access the index (i.e. GET) for a route I get:

Errno::EACCES in Crb_agendas#index

Showing /var/www/crbagenda/app/views/layouts/application.html.erb where line #5 raised:

Permission denied - /var/www/crbagenda/tmp/cache/assets/E2C

Extracted source (around line #5):

2: <html>
3: <head>
4:   <title>CrbAgendas</title>
5:   <%= stylesheet_link_tag "application" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>

Rails.root: /var/www/crbagenda

When I go to the path mentioned (/var/www/crbagenda/tmp/cache/assets/E2C) there is no E2C folder and root (what apache is running as) owns the assets dir... not sure what I did wrong here.... or what else I could show to help.

Disclose answered 14/11, 2011 at 20:43 Comment(1)
For us, we got this when switching from uglifier to terser for JS compression. I had to run rails assets:clobber in Staging/Production and then re-deploy and everything was fine.Burlingame
P
19

I found this post when I encountered this error and running chmod 777 is not the solution here.

You need to do some research on how to enable group permissions and configure apaches settings appropriately. Here is a Stack Exchange thread that details this rather well and contains useful links. Make sure apache has read, write and execute access to the appropriate directories but don't simply let ANYONE modify the directory. Locate your systems apache group and run chown and chmod -g+[What permissions apache needs goes here] I would suggest not running this with the -R option and to actively look into which permission apache needs for specific directories. Link to Stack Exchange thread regarding apache permissions and permissions in general

Pacesetter answered 3/10, 2012 at 0:41 Comment(1)
This does not seem to adequately answer the question. It's probably also the case that permissions will want to be applied with find, e.g. find . -type f -not -user $USER -exec chown $UID:$GID {} \;Holliholliday
D
18

Update: Yeah this answer came from ignorance and then seemed to gain traction. Anyway, the real answer can be found in Austen Tomek's answer

Hacked around this by doing chmod 777 on the tmp directory so I am guessing it is my ignorance on the user/permissions settings.

Disclose answered 15/11, 2011 at 11:17 Comment(6)
This is fixed my problem also. Thanks.Gomel
This is really not the way to solve this. It's like saying your key won't open your front door so you just removed the lock and called it a day. See Austen's answer for a better approach.Burlingame
@JoshPinter It is rather embarrassing how much traction my answer received. I updated mine to add a link pointing to Austen's answer.Disclose
@Disclose Nice one. To be fair, I did this as a temp fix in production just to keep the application up but then corrected the permissions during a maintenance period later. Thanks for updating your answer.Burlingame
If you even say in your update answer, that another one is more correct, it would be great of you would actually chose the other question as the accepted answer. This might help keep people from removing their locks without understanding it...Character
@Disclose Thank you! Stack Overflow keeps its quality through actions like this.Character
P
16

I deleted the tmp folder completely, that worked for me. It just gets regenerated by the web server.

Palacio answered 26/7, 2012 at 2:0 Comment(1)
I'm working on Windows 10 Enterprise and this worked for me too. However, it did not work for me on Windows 10 Home where I had to change permissions in the project directoryClownery
F
8

For me it was useful:

sudo chown -R username app_path
Fajardo answered 23/11, 2015 at 7:19 Comment(0)
M
5

Just run chown on project folder

chown -R www-data /var/www/
Montsaintmichel answered 26/6, 2014 at 17:14 Comment(0)
A
3

I had this same issue when working on a Rails 6 application in Ubuntu 20.04.

Each time I run the command rails assets:clobber to remove the old assets in public/assets completely, I get the error:

errno::enotempty: directory not empty @ dir_s_rmdir

errno::eacces: permission denied @ apply2files

And the logs pointed the path to the file causing it, which in my a case was the public/packs/manifest.json file.

I tried deleting it or changing permission but nothing worked. I also tried deleting the tmp directory in the project, but it did not work.

Here's how I fixed it:

I listed all the files and directories in that directory using the ls -lh command, which gave me this output:

-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 404.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.7K Oct  6 20:29 422.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem 1.6K Oct  6 20:29 500.html
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon.png
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 apple-touch-icon-precomposed.png
drwxr-xr-x 3 promisechukwuenyem promisechukwuenyem 4.0K Oct 13 09:20 armstrong_tools
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem    0 Oct  6 20:29 favicon.ico
drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs
-rw-rw-r-- 1 promisechukwuenyem promisechukwuenyem   99 Oct  6 20:29 robots.txt

I realized that the packs directory had root ownership which was seperate from persmission of other files and directories:

drwxr-xr-x 3 root               root               4.0K Oct  8 13:06 packs

I simply ran the command below to change the ownership from root to promisechukwuenyem:

sudo chown -R promisechukwuenyem:promisechukwuenyem packs/

Now when I ran the command rails assets:clobber to remove the old assets in public/assets completely, it worked just fine.

That's all.

I hope this helps

Audsley answered 13/10, 2020 at 12:47 Comment(0)
F
1

Im using windows vs code with a ubuntu subsystem as the terminal.

I had to move my project folder from the ubuntu sub system area to the windows area.. so everytime I run stuff with ubuntu I have to type cd /mnt/c/projects/my_app

it seems to allow the apps to run and the db/ server stuff to operate alright..

Rhys

Fastidious answered 19/4, 2018 at 9:55 Comment(1)
Please have a look at the other provided answers.Andrel
M
1

On windows just open your cmd as Administrator and execute your gem install "lib" command

Marquise answered 1/6, 2019 at 13:27 Comment(0)
C
0

Thanks to the posts above, I got to solve my own problem too. Personally, an important folder was labeled "Hidden" (follow the ERROR path Error: Permission denied - .../_netrc (Errno::EACCES) As soon as I right-clicked and set its folder options to NOT HIDDEN, then everything worked fine!

Caritacaritas answered 5/7, 2014 at 15:21 Comment(0)
S
-1

In my case changing rights nor ownership of the directory didn't help (well it was necessary). Turned out that Selinux kicked in (by default enabled in Fedora) and disabling was the cure:

$ sudo setenforce 0

To make the change permanent one has to change the settings in the /etc/selinux/config file:

SELINUX=disabled
Synthiasyntonic answered 25/9, 2014 at 17:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.