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.

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

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装