Ruby-on-rails tmp 中的权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7524262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:01:07  来源:igfitidea点击:

Permission denied in tmp

ruby-on-railsruby

提问by leonel

I just deployed a Rails 3 app with Ruby 1.9.2. I have been getting several errors.

我刚刚使用 Ruby 1.9.2 部署了一个 Rails 3 应用程序。我遇到了几个错误。

  1. application.csswasn't compiled. so I set pre compilation in production.rbto false;
  2. Then I got: cannot generate tempfile, so I did rake tmp:clear;
  3. 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.
  1. application.css没有编译。所以我将预编译设置production.rb为 false;
  2. 然后我得到了:cannot generate tempfile,所以我做了rake tmp:clear
  3. 现在我明白了ActionView::Template::Error (Permission denied - /srv/www/appname/tmp/cache/assets):,但我无法解决这个问题。

Please help.

请帮忙。

回答by Adam Eberlin

If the user:grouprunning your web server is http:httpand it's running on *nix, do this:

如果user:group正在运行您的 Web 服务器http:http并且它在 *nix 上运行,请执行以下操作:

sudo chown -R http:http /srv/www/appname/

Also, silly question, but does /tmp/cache/assets exist?

另外,愚蠢的问题,但是 /tmp/cache/assets 是否存在?

And, if so, as @leonelpoints out, you may also need to change the permissions:

而且,如果是这样,正如@leonel指出的那样,您可能还需要更改权限:

chmod 777 /srv/www/appname/tmp/cache

Be careful setting 777permissions on anything. Only do this to verify a permissions issue, then reset to the most minimal permissions necessary.

小心设置777任何权限。这样做只是为了验证权限问题,然后重置为所需的最低权限。

回答by Vanuan

Most likely you're running your app under apache passenger.

很可能您正在 apache 乘客下运行您的应用程序。

You have to change the owner of config/environment.rb to somebody who has permissions to your app's folder.

您必须将 config/environment.rb 的所有者更改为对您的应用程序文件夹具有权限的人。

chown -R www-data:www-data /path/to/app

回答by Spyros

  1. 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
    
  2. In your console, run rake tmp:cache:clear

  3. Restart your application.

  1. 使项目的 tmp 文件夹可写:

    chown -R group:user /path/to/rails/app/tmp
    chmod -R 777 /path/to/rails/app/tmp
    
  2. 在您的控制台中,运行 rake tmp:cache:clear

  3. 重新启动您的应用程序。

回答by Marc Plano-Lesay

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/assetsand tell us the user running the webserver ?

您可能没有使用现在运行服务器的用户创建 Rails 应用程序。你能粘贴输出ls -alh /srv/www/appname/tmp/cache/assets并告诉我们运行网络服务器的用户吗?

回答by Sachin Siddaveerappa

I encountered this error recently. Apache was not able to write to tmp directory

我最近遇到了这个错误。Apache 无法写入 tmp 目录

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'

无法生成临时文件 /tmp/RackRewindableInput2xxxxxxxxxxxxxxxxx' /app-lib/lib/ruby/1.8/tempfile.rb:52:in初始化'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.

我检查了 tmp 目录的权限,它允许所有组写入它。我更改了 tmp 目录的所有者,它也没有解决错误。

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.

罪魁祸首是 tmp 目录充满了太多大文件,看起来 apache 不知何故没有足够的空间来编写这个新文件。清除所有临时文件和旧文件。它解决了这个问题。

回答by pensebien

Now for those of us that are using windows - If you are an administrator and see this error

现在对于我们这些使用 Windows 的人 - 如果您是管理员并看到此错误

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.

然后是 Windows 上的权限和所有权设置问题。您可以转到应用程序上的 tmp 文件夹,并授予您自己(用户)对该文件夹的 **读取、写入和执行 ** 权限。点击[此处][1]查看如何授予权限。

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.

然后重启你的服务器。

回答by Jai Kumar Rajput

We need to grant permissions to access the required directory for the system root user

我们需要为系统root用户授予访问所需目录的权限

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 777gives everybody read, write and execute rights which for most problems is definitively too much.

chmod 777给每个人读、写和执行的权限,这对于大多数问题来说绝对是太多了。

回答by tcgumus

I think a better solution without giving everyone manage rights to tmp folder is like that:

我认为一个更好的解决方案是不给每个人管理 tmp 文件夹的权限:

 sudo rake tmp:cache:clear

This will clear the temp folder and when you run rails serveragain it won't give error.

这将清除临时文件夹,当您rails server再次运行时,它不会出错。

回答by Naiguel Developer

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

在我的本地主机中,它给出了这个错误,该命令chmod 777 C:/Sites/project_name/tmp/cache/解决了我的问题。

回答by user2271779

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:

很可能您授予了应用程序主文件夹read and execute mode 的权限。但是,为了从您的应用程序生成新文件,您还需要为所需文件夹授予写入权限。例如:yUML 使用 tmp 文件夹生成文件。我给了 tmp 文件夹写权限:

chmod -R 777 /usr/share/nginx/html/yuml_product/tmp

chmod -R 777 /usr/share/nginx/html/yuml_product/tmp

solved my problem.

解决了我的问题。