[英]Problems with php shell_exec permissions
I'm running as www-data
and I'm trying to execute a shell script using shell_exec(/foobar/script/myscript.sh)
, but I'm getting the following error when the script attempts to write to a log file 我正在以
www-data
身份运行,并尝试使用shell_exec(/foobar/script/myscript.sh)
执行Shell脚本,但是当脚本尝试写入日志文件时出现以下错误
cannot create /foobar/foo.log: Permission denied
However, I don't run into any problems if I try running the script directly from the terminal. 但是,如果我尝试直接从终端运行脚本,则不会遇到任何问题。 ie
即
$ sudo su www-data
$ /foobar/script/myscript.sh
$
Any idea what could be going on here? 知道这里会发生什么吗?
I should also add that I added www-data to the group mybar and that this is what's showing up when I list the directory 我还应该补充一点,我将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
I think there can be two options: 我认为可以有两种选择:
This works for me: 这对我有用:
sudo chown www-data:www-data -R foobar/
The directory you are trying to create the file in must belong to whoever is executing the command. 您试图在其中创建文件的目录必须属于执行命令的任何人。
You can type: 您可以输入:
ls -la
to see who it belongs to. 看看它属于谁。
You should see something like this: 您应该会看到以下内容:
drwxr-xr-x 8 jack jack 4096 Jul 22 11:36 application
When I am logged into my ubuntu machine I am logged in as jack@jack
so I can create files in the following directory without issuing the sudo
command: 当我登录到ubuntu机器时,我以
jack@jack
身份登录,因此我可以在以下目录中创建文件,而无需发出sudo
命令:
drwxr-xr-x 8 jack jack 4096 Jul 22 11:36 application
because it is owned by the current user. 因为它是当前用户拥有的。
When you try running a script that is executed by visiting a webpage. 当您尝试运行通过访问网页执行的脚本时。
www-data
is the user that is executing the command so any directory or file that you are trying to create/modify/delete must be owned by www-data
. www-data
是执行命令的用户,因此您试图创建/修改/删除的任何目录或文件都必须由www-data
拥有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.