30

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.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
ScottJShea
  • 7,041
  • 11
  • 44
  • 67
  • 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. – Joshua Pinter Sep 27 '22 at 16:05

10 Answers10

17

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

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Austen Tomek
  • 248
  • 3
  • 7
  • 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 {} \;` – Kaia Leahy Oct 23 '18 at 06:04
17

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.

Community
  • 1
  • 1
ScottJShea
  • 7,041
  • 11
  • 44
  • 67
  • This is fixed my problem also. Thanks. – alexganose Feb 08 '12 at 14:38
  • 4
    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. – Joshua Pinter May 15 '13 at 16:55
  • 1
    @JoshPinter It is rather embarrassing how much traction my answer received. I updated mine to add a link pointing to Austen's answer. – ScottJShea May 16 '13 at 06:19
  • @ScottJShea 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. – Joshua Pinter May 17 '13 at 16:54
  • 1
    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... – Holger Just Jul 05 '14 at 15:38
  • @ScottJShea Thank you! Stack Overflow keeps its quality through actions like this. – Holger Just Jul 06 '14 at 11:09
16

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

Charlie
  • 10,227
  • 10
  • 51
  • 92
  • 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 directory – Casivio Aug 26 '22 at 17:21
8

For me it was useful:

sudo chown -R username app_path
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Marco Roth
  • 184
  • 4
  • 11
5

Just run chown on project folder

chown -R www-data /var/www/
Tim Kozak
  • 4,026
  • 39
  • 44
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

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
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

1

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

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!

Terry Bu
  • 889
  • 1
  • 14
  • 31
-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
Rajish
  • 6,755
  • 4
  • 34
  • 51