2

我正在运行www-data并且我正在尝试使用执行 shell 脚本shell_exec(/foobar/script/myscript.sh),但是当脚本尝试写入日志文件时出现以下错误

cannot create /foobar/foo.log: Permission denied 

但是,如果我尝试直接从终端运行脚本,我不会遇到任何问题。IE

$ sudo su www-data
$ /foobar/script/myscript.sh
$

知道这里会发生什么吗?

我还应该补充一点,我将 www-data 添加到 mybar 组中,这就是我列出目录时显示的内容

drwxrwxr-x 3 mybar mybar  4096 May 14 14:18 foobar     # ls -l /


-rw-rw-r-- 1 mybar mybar 2824 May 15 09:57 foo.log     # ls -l /foobar
4

2 回答 2

1

I think there can be two options:

  1. web-server and php-fpm are run under different users (by default that should not be). Try echo shell_exec('whoami');
  2. You have added www-data to mybar after php-fpm process had been started so it still "doesn't know" that it is (then I think restart of fpm should help).
于 2013-05-15T17:50:43.923 回答
1

这对我有用:

sudo chown www-data:www-data -R foobar/

您尝试在其中创建文件的目录必须属于执行命令的人。

您可以键入:

ls -la 

看看它属于谁。

您应该看到如下内容:

drwxr-xr-x  8 jack jack  4096 Jul 22 11:36 application

当我登录到我的 ubuntu 机器时,我已登录,jack@jack因此我可以在以下目录中创建文件而无需发出sudo命令:

drwxr-xr-x  8 jack jack  4096 Jul 22 11:36 application

因为它归当前用户所有。

当您尝试运行通过访问网页执行的脚本时。www-data是执行命令的用户,因此您尝试创建/修改/删除的任何目录或文件都必须归www-data.

于 2014-07-22T13:00:59.213 回答