【发布时间】:2019-09-17 07:40:38
【问题描述】:
我目前正在为我的 gitlab 存储库创建一个 webhook 脚本。该脚本将运行一些 shell 命令(如 git)来克隆存储库。我像这样运行shell命令
$output = shell_exec('which git');
var_dump($output);// NULL
但是当我直接在服务器上的 bash 中运行 which git 时,没有输出并且安装了 git。
我的服务器是安装了 cpanel 和 whm 的 amazon ec2 instance centos 7。
我已经检查了它是否在 whm 上的 php ini 上被禁用,但它没有。
shell_exec 没有输出任何东西的原因可能是什么
编辑:
与
相同exec('which git', $output);
var_dump($output); // NULL
即使我在命令中添加了2>&1 以将其输出到stderr 和stdout。
【问题讨论】:
-
运行 webhook 的用户是否有 git?如果你做
shell_exec("whoami");是你期望的用户吗 -
@chiliNUT 这是我运行该命令时的问题,也没有输出,所以我无法识别用户。
-
如果您为未安装 git 的用户运行
which git,则预期结果将是null。当您运行whoami时,它也返回了null?
标签: php shell-exec