php shell_exec权限被拒绝 [英] php shell_exec permission denied
问题描述
shell_exec("touch /Users/Nerses/Downloads/ads.txt 2>&1")
我的PHP exec(shel_exec)函数有问题.它说我没有执行该命令的权限.
I have a problem with the PHP exec(shel_exec) function. It says that I do not have permissions to execute the command.
如何打开这些权限?
推荐答案
您的PHP代码正在尝试访问/Users/Nerses/Downloads/ads.txt
,如您所见,该文件夹由名为"Nerses"的用户拥有.
Your PHP code is trying to access /Users/Nerses/Downloads/ads.txt
, as you can see, that folder is owned by the user called "Nerses".
他是唯一可以访问它的人(和根用户)(除非您更改该文件夹的权限).
He is the only one (and root) who can access it (unless you change the permissions to that folder).
通常,执行shell_exec
的用户称为www-data
,因此请授予该用户权限,或更改该文件夹中的权限.
Normally, the user that executes shell_exec
is called www-data
, so give permissions to that user, or change the ones in that folder.
其他选项是执行
shell_exec('sudo -S YOUR COMMAND');
您可以通过命令签出您使用的用户
You can check out the user you use with the command
shell_exec('whoami');
这篇关于php shell_exec权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!