Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使www拥有root权限,php exec也会失败_Php_Macos_Apache_Exec_Root - Fatal编程技术网

即使www拥有root权限,php exec也会失败

即使www拥有root权限,php exec也会失败,php,macos,apache,exec,root,Php,Macos,Apache,Exec,Root,我想通过php exec命令打开存储在MAC OS X 10.8服务器上的文本文件。 为此,我首先创建了一个名为dummy.txt的虚拟文本文件,其中包含一些文本。 然后,我创建了一个名为script.sh的脚本文件,包括以下内容: open -a /Applications/TextEdit.app /Library/WebServer/Documents/Secured/upload/dummy.txt exec('/Library/WebServer/Documents/Secured/

我想通过php exec命令打开存储在MAC OS X 10.8服务器上的文本文件。 为此,我首先创建了一个名为dummy.txt的虚拟文本文件,其中包含一些文本。 然后,我创建了一个名为script.sh的脚本文件,包括以下内容:

open -a /Applications/TextEdit.app /Library/WebServer/Documents/Secured/upload/dummy.txt
exec('/Library/WebServer/Documents/Secured/upload/script.sh');
然后创建了一个测试php文件,包括以下内容:

open -a /Applications/TextEdit.app /Library/WebServer/Documents/Secured/upload/dummy.txt
exec('/Library/WebServer/Documents/Secured/upload/script.sh');
Mac上的Apache用户“_www”被授予了所有文件的所有权,并将所有文件的所有权授予了wheel dummy.txt和test.php的权限为644,script.sh文件的权限为755

以标准用户身份登录,从终端运行script.sh将显示TextEdit程序打开dummy.txt文件

以root用户身份登录,为标准用户重试,如下所示:

su - myuser -c "/Library/WebServer/Documents/Secured/upload/script.sh"
将正常显示编辑器。但是,

su - _www -c "/Library/WebServer/Documents/Secured/upload/script.sh"
无法运行文本编辑器

当我通过客户机浏览器访问test.php时,它也不会显示文本编辑器

但是,通过客户端计算机进行访问会在apache错误日志中显示以下错误:

LSOpenURLsWithRole() failed with error -10810 for the file /Library/WebServer/Documents/Secured/upload/dummy.txt
使用所有权限将www添加到sudoers文件(如下所示)并没有解决我的问题

_www    ALL=(ALL) NOPASSWD: ALL
我甚至尝试在sudoers中添加以下行:

Defaults:_www !requiretty
以及在passwd文件中将_wwwuser的shell从false设置为sh

他们都没有工作。我还要补充一点,在这一点上,安全不是我关心的问题。我只想成功地运行它。然后我会处理安全隐患

有什么建议吗?
提前感谢

打开命令(以及任何其他打开文本编辑的方式)只能在GUI会话的上下文中工作;web服务器不是会话的一部分,因此无法在会话中打开某些内容

有很多方法可以解决这个问题,但它们确实很难看。它们包括从www用户切换到root用户(可能使用
sudo
),附加到GUI会话中运行的某个进程的上下文(
launchctl bsexec somePID somecommand
),然后可能还必须切换到会话所有者(
sudo-u loggedinuser
),然后运行open命令

这很难看,因为你试图做的事情真的很不自然。让web服务器中的某些东西触发GUI编辑会话真的没有任何意义。请重新思考你想做什么以及为什么