【发布时间】:2015-05-18 05:00:22
【问题描述】:
我已经用 git 和我的服务器(godaddy 共享主机)设置了关于 SSH 密钥的所有内容,并且可以使用git pull git@github.com:username/reponame.git通过 SSH 成功更新服务器
我正在尝试使用 simple-php-git-deploy 在我提交对我的 git 存储库的更改时自动更新测试服务器
当下面的 php 脚本摘录运行 shell_exec('which git') 时,函数返回一个空字符串。
由于我可以在 SSH 中运行 git 命令,我觉得这一定是权限问题。
我尝试运行chmod 755 foldertoupdate,没有任何变化。
我需要做什么才能让 php(或当前的 apache 用户)调用 git 命令?
// Check if the required programs are available
$requiredBinaries = array('git', 'rsync');
//.....
foreach ($requiredBinaries as $command) {
$path = trim(shell_exec('which '.$command));
if ($path == '') {
die(sprintf('<div class="error"><b>%s</b> not available. It needs to be installed on the server for this script to work.</div><br> Output was: %s', $command,$path )); // this check fails on the first element, "git" claiming git is not installed
} else {
$version = explode("\n", shell_exec($command.' --version'));
printf('<b>%s</b> : %s'."\n"
, $path
, $version[0]
);
}
}
更多信息:
- 我正在更新的文件夹位于
~/html/TeamBoard - 我从中调用代码的文件位于
~/html/TeamBoard/deploy.php
【问题讨论】:
-
您的脚本从哪个目录运行,您是否能够从该位置成功发出命令行 git 命令?
-
@TimBiegeleisen php 文件位于我要更新的文件夹中,
~/html/TeamBoard是文件夹,文件位于~/html/TeamBoard/deploy.php。当cd进入html文件夹时,我能够将repo 克隆到这个文件夹,但现在我尝试做git pull我得到你要求从远程'git@github.com:DelightedD0D/TeamBoard .git',但没有指定分支。因为这不是您当前分支的默认配置远程,所以您必须在命令行上指定一个分支。 -
apache 用户(或任何 php 在浏览器中运行的用户)需要相关文件夹/二进制文件的权限
-
@Anthony 你能告诉我如何改变吗?我以为
chmod 755 foldertoupdate会起作用,但它没有。是否需要为实际安装 git 的文件夹设置访问权限? -
我不确定,但请记住,如果 apache 在共享环境中运行,那么让它工作将使托管在同一机器上的任何其他站点能够在您的 repo 文件夹上执行 git 命令。也许看看像 suphp 之类的东西?