Permission denied in tmp - ruby-on-rails

I just deployed a Rails 3 app with Ruby 1.9.2. I have been getting several errors.
application.css wasn't compiled. so I set pre compilation in production.rb to false;
Then I got: cannot generate tempfile, so I did rake tmp:clear;
And now I get ActionView::Template::Error (Permission denied - /srv/www/appname/tmp/cache/assets): and I haven't been able to fix this one.
Please help.

If the user:group running your web server is http:http and it's running on *nix, do this:
sudo chown -R http:http /srv/www/appname/
Also, silly question, but does /tmp/cache/assets exist?
And, if so, as #leonel points out, you may also need to change the permissions:
chmod 777 /srv/www/appname/tmp/cache
Be careful setting 777 permissions on anything. Only do this to verify a permissions issue, then reset to the most minimal permissions necessary.

Most likely you're running your app under apache passenger.
You have to change the owner of config/environment.rb to somebody who has permissions to your app's folder.
chown -R www-data:www-data /path/to/app

Make the tmp folder of your project writable:
chown -R group:user /path/to/rails/app/tmp
chmod -R 777 /path/to/rails/app/tmp
In your console, run rake tmp:cache:clear
Restart your application.

You probably didn't create your Rails application with the user running the server now. Can you paste the output of ls -alh /srv/www/appname/tmp/cache/assets and tell us the user running the webserver ?

Now for those of us that are using windows
- If you are an administrator and see this error
ActionView::Template::Error (Permission denied # utime_failed) C:/User/..../tmp/cache/assets/sprochets/v3.0/E5/E5PZx-mq8.cache
Then it is Permission and Ownership setting issue on Windows.
You can go to the tmp folder on your application and give yourself(User) permission to **Read, Write and Execute ** on the folder.
Click [here][1] to view how to give permissions.
Quick Fix. Open your terminal and run the following command as an administrator
takeown /f <location of your app tmp folder> /r /d y
Then Restart your server.

I encountered this error recently. Apache was not able to write to tmp directory
cannot generate tempfile
/tmp/RackRewindableInput2xxxxxxxxxxxxxxxxx'
/app-lib/lib/ruby/1.8/tempfile.rb:52:ininitialize'
app-dir/vendor/gems/rack-1.0.1/lib/rack/rewindable_input.rb:73:in new'
app-dir/vendor/gems/rack-1.0.1/lib/rack/rewindable_input.rb:73:inmake_rewindable'
app-dir/vendor/gems/rack-1.0.1/lib/rack/rewindable_input.rb:26:in read'
app-dir/vendor/gems/rack-1.0.1/lib/rack/request.rb:134:inPOST'
I checked permission of tmp directory and it had permission to all groups to write to it.
I changed owner of tmp directory and it didn't resolve the error either.
The culprit was tmp directory was filled with too many large files, and looks like somehow apache didn't had enough space to write this new file.
Cleared all temp and old files. It sorted out the issue.

We need to grant permissions to access the required directory for the system root user
sudo chmod 777 -R your_project_directory_to_be_access
In your case you can use:
sudo chmod 777 -R /srv/www/appname/tmp/
For security reasons, just keep in your mind:
chmod 777 gives everybody read, write and execute rights which for most problems is definitively too much.

I think a better solution without giving everyone manage rights to tmp folder is like that:
sudo rake tmp:cache:clear
This will clear the temp folder and when you run rails server again it won't give error.

In my localhost it gave this error, and the command chmod 777 C:/Sites/project_name/tmp/cache/ solved my problem.

Most probably you gave permission to your app's main folder read and execute mode. However, in order to generate new files from your app, you also need to give write permission for required folder. For example: yUML uses tmp folder for generating files. I gave tmp folder write permission:
chmod -R 777 /usr/share/nginx/html/yuml_product/tmp
solved my problem.

Related

My Rails apps all suddenly became read-only

I was working on my rails app, left it for a while, came back, and tried to restart my server. In response, I got back this error:
Rails Error: Unable to access log file. Please ensure that /home/user/app/log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
I have no idea what I could have done to cause this. I never even touched my log directory. I tried to run chmod 0666 /home/user/app/log/development.log and then various other chmod commands, like chmod 0664 and chmod 777. Each time I got back:
chmod: changing permissions of ‘/home/user/app/log/development.log’: Read-only file system
but I always got back the same error from rails s.
Then I gave up and switched to a different app I'm working on, but after running rails s for that app, I got back basically the same error:
Rails Error: Unable to access log file. Please ensure that /home/user/sweat/log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
What is going on? I'm using Ubuntu 14.04.
UPDATE
Running sudo chmod 777 -R log gives me back this:
sudo: unable to open /var/lib/sudo/user/1: No such file or directory
chmod: changing permissions of ‘log’: Read-only file system
chmod: changing permissions of ‘log/development.log’: Read-only file system
chmod: changing permissions of ‘log/.keep’: Read-only file system
if you are using Linux!
try this => cd home/user/app
then => sudo chmod 777 -R log
I hope this helps you!

How to set right permission to Linux file?

I wanted to know how can I set right permission for my file /log/production.log? Everyone is saying just use chmod or chown but no one explains what I should wright after these commands. I am beginner and would appreciate if you could explain.
In my particular example I have rails app on production server where I need to set permission to production.log file in /var/www/my_app/log/ directory.
Here is what documentation is asking from me:
By default, Phusion Passenger runs Rails applications as the owner of
config.ru. So the log file can only be written to if that user has
write permission to the log file. Please chmod or chown your log file
accordingly.
Hope you can help. Thanks.
Try chmod 0660 production.log and take a look at this explanation/diagram of chmod.
chmod allows change the permissions of a file or a directory. Exists three basic permissions (read,write,execute) for three differents groups (owner,group,other).
chown allows change who is the owner of a file or a directory.
I recommend you use chmod 640. Looking the syntax of chmod here you're defining the production.log's owner (usually root) can read and write this file. If you want, you can give read-access for all users of the same group of the owner. But you shouldn't offer permissions for other people, even less in a production environment.
I would create a deploy user for your application, say myapp (doesn't particularly matter what the name is). The use this user to deploy/manage your application. Assuming username myapp
chown -R myapp:myapp /var/www/my_app
and then restart nginx/passenger. This will cause passenger to run as the myapp user, and allow it to write logs under the logs directory. (Also make sure that you don't have /var/www as the docroot, accessible outside of passenger as it can cause information leakage)
another option, if the server isn't shared, is that you can run as the www user. so
chown -R www:www /var/www/my_app
which should allow the process to write to your logs.

Rails could not find a temporary directory (ArgumentError)

I'm uploading my Rails proyect to a Ubuntu Server running 12.04LTS and I can't seem to fix this issue! Whether I do a bundle install or try to use the whenever gem I get that error! I've read a lot but still I'm unable to fix it
/lib/ruby/2.0.0/tmpdir.rb:34:in `tmpdir': could not find a temporary directory (ArgumentError)
And my ls -la of the / folder
Any ideas?
P.s I tried chmod -R 777 on /tmp with no luck
The short answer is to just run this like #hagello suggests.
chmod +t /tmp
Then it should start working again.
edit: As suggested in the comments just run
chmod +t /tmp
========
Old answer:
Your Ubuntu installation probably doesn't have TMPDIR set. You should set that variable in your startup.
This link has more information on environment variables in Ubuntu: https://help.ubuntu.com/community/EnvironmentVariables

Why am I getting 'Permission Denied' on my static assets?

Question basically says it all. When I try to access my calendar page (which contains events), I get the following error:
Permission denied - /Users/usernam/sitter/tmp/cache/assets/development/sass
(in /Users/username/sitter/app/assets/stylesheets/events.css.scss)
i've done a chmod 777 on all directories in my rails directory (i.e in myapp directory, i've done chmod 777 *).
Not sure what I should be doing instead or in addition.
Add a -R to your chmod. Simply adding the star will only do the files. Chmod -R 777 * should work. Although you may have some ownership issues that need to be addressed. I would look into using chown instead of granting all access to everyone.

Rails application needs access to a tmp directory

I'm using the fleximage plugin with a rails application. It throws an error message because it doesn't have access to the tmp directory. When I chmod 777 the tmp directory everything works fine. But if I chmod 666 it doesn't work.
What are the proper permissions for folder that needs to be accessed by rails/apache? if chmod 777, am I opening a security hole? wouldn't 777 give execute privileges?
Also, currently the owner of the tmp folder is root, should this be changed to www-data? Why would it matter who the owner of the folder is?
For a folder, the execute permission is what you need to be able to cd into it, it has nothing to do with executing programs.
Changing the owner to www-data is much safer, then you can use the 700 permission - meaning that only www-data can use this folder. With 777, www-data can also use it -- but so can everyone else which is not what you want (if this is an application-specific tmp folder that is, don't change the owner of /tmp).

Resources