我有一个简单的 PHP 脚本:
exec('git pull origin master', $shell_output, $output);
print_r($shell_output);
print_r($output)
当我通过 CLI php git.php
调用它时,它工作正常。我得到了预期的输出,返回值为 0。当我通过网络浏览器访问该页面时,它失败了,返回值为 1。
我已将文件权限设置为 777,并确保 php.ini
不会阻止 exec()
函数。
最佳答案
CLI 使用当前登录用户(您)的凭据运行,它很可能与 Web 服务器进程使用的不同。执行 exec('whoami')
等来验证。
关于从浏览器而非 CLI 调用时 PHP exec 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13097550/