Cron作业和文件夹权限 - 拒绝权限 [英] Cron job and folders permissions - permission denied

查看:632
本文介绍了Cron作业和文件夹权限 - 拒绝权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在webroot上面的文件夹,用于临时存储由php web应用程序生成的用户文件。这些文件可以是将要附加到电子邮件的PDF。

I have a folder above the webroot that is used to temporarily store user files generated by a php web application. The files may, for example, be PDF's that are going to be attached to emails.

文件夹权限设置为rwxr-xr-x(0755)。从Web应用程序执行过程时,文件将被写入此文件夹,没有任何问题。

The folder permissions are set to rwxr-xr-x (0755). When executing a procedure from the web application, the files get written to this folder without any issues.

我现在还设置了一个cron作业,调用php脚本执行与上述完全相同的过程。但是,由于权限失败,PDF无法保存到上述文件夹中 - cron作业报告了权限被拒绝错误。

I have now also set up a cron job that calls the php script to execute that exact same procedure as above. However, the PDF cannot be saved into the above folder due to failed permissions - the cron job reports back a permission denied error.

我已经尝试将文件夹权限设置为0775,仍然获得拒绝权限。然而,当权限是0777,然后cron工作然后工作正常。

I have tried setting the folder permissions to 0775 and still get a permission denied. However, when the permissions are 0777, then the cron job then works fine.

这似乎很奇怪我 - 为什么cron获得在0755拒绝的权限,但它通过网络应用程序可以正常工作?

This seems very strange to me - why does the cron get a permission denied at 0755 but it works fine through the web app?

推荐答案

可能的答案是cron作业在您的用户下执行 - 通过apache(或www-data或者无人或您的web服务器运行的任何用户)。

The probable answer is that the cron job executes under your user - and the directory is owned by apache (or www-data or nobody or whatever user your web server runs as).

要使其工作,可以设置cron作为运行Web服务器用户。
这样的东西:

To get it to work, you could set up the cron job to run as the web server user. Something like this:

su -l www-data -c 'crontab -e'

或者,您可以将权限更改为775(所有者和组的读写执行,其他),并将文件夹的组所有权设置为运行cron作业的用户。

Alternatively, you could change the permissions to 775 (read-write-execute for the owner and group, and read-execute for others) and set the group ownership of the folder to the user running the cron job.

但是,您必须确保如果您删除了某些内容,文件夹,它是由apache创建的,你仍然可能遇到问题(apache会创建一个它自己拥有的文件,然后你的用户无法删除它,无论目录权限。

However, you have to make sure that if you're deleting something or descending into folder which is created by apache, you could still run into problems (apache would create a file which it itself owns, and your user cannot delete it then, regardless of the directory permissions.

您还可以查看一些东西,如suphp或什么是最新的 - 网络服务器进程是根据您的用户名运行,这取决于您的系统架构。

You could also look at some stuff like suphp or whatever is up to date - where the web server processes are ran under your username, depending on your system architecture.

这篇关于Cron作业和文件夹权限 - 拒绝权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆