dongyi0114 2019-04-14 11:42
浏览 96
已采纳

如何为apache提供cmd权限?

I'm working on a php application that pulls github repositories to the server. Github webhooks call the php files.

I want to execute a cmd command using php. I assume I need apache permissions but I don't know how to give them.

The php code below creates an mkdir.bat and a gitclone.bat and runs them. The mkdir runs successfully, it creates an empty folder, but the gitclone doesn't create any folders or files. When I run the gitclone manually it does create folders and files.

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");
  • 写回答

1条回答 默认 最新

  • dqotv26286 2019-04-14 12:58
    关注

    I executed your code in my computer

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

    the extra code is to check the output from cmd and it returned "git command not exsists" so you only have to add a line as

    <?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);
    ?>
    

    This was working properly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?