【问题标题】:How do I give cmd permissions to apache?如何将 cmd 权限授予 apache?
【发布时间】:2019-04-14 11:42:21
【问题描述】:

我正在开发一个将 github 存储库拉到服务器的 php 应用程序。 Github webhooks 调用 php 文件。

我想使用 php 执行一个 cmd 命令。我假设我需要 apache 权限,但我不知道如何授予它们。

下面的 php 代码创建一个 mkdir.bat 和一个 gitclone.bat 并运行它们。 mkdir 运行成功,它会创建一个空文件夹,但 gitclone 不会创建任何文件夹或文件。当我手动运行gitclone 时,它会创建文件夹和文件。

file_put_contents("mkdir.bat", "mkdir test");
exec("mkdir.bat");

file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat");

【问题讨论】:

  • 你不能使用exec函数吗?
  • 我可以使用 php exec 函数来启动一个 bat,它有一个像 mkdir 这样的简单命令,但我不能将它用于 git clone

标签: php apache permissions


【解决方案1】:

我在我的电脑上执行了你的代码

file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat 2>&1",$o);
print_r($o);

额外的代码是检查 cmd 的输出,它返回“git 命令不存在” 所以你只需要添加一行作为

<?php
putenv("PATH=C:\Program Files\Git\cmd");
file_put_contents("gitclone.bat", "git clone https://github.com/gutyina700/WPTG.git");
exec("gitclone.bat 2>&1",$o);
print_r($o);
?>

这工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    相关资源
    最近更新 更多