我添加了路径变量,git在shell/terminal上运行得很好,但当我尝试在XAMPP服务器上使用php-exec时,我收到了这个错误。
'git' is not recognized as an internal or external command, operable program or batch file.
我的php代码在这里:
<?php
echo shell_exec("git pull https://github.com/Leadera/ecoman_repo.git 2>&1");
?>
当我从cmd发出gitpull请求时,它可以工作,但在浏览器中我得到了一个错误。这应该是什么问题?
谨致问候,金枪鱼
shell_exec
在XAMPP目录中搜索git
命令时,应使用git 的绝对路径
<?php
echo shell_exec("/bin/git pull https://github.com/Leadera/ecoman_repo.git 2>&1");
?>
Alexandre的回答解决了这个问题,但我找到了另一种方法。
我用了
设置PATH=%PATH%;C: ''Program Files(x86)''Git''bin(在窗口中)
在xampp命令面板中为xampp添加路径的代码。它也解决了我的问题。