Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php shell_exec(';哪个git';)在Godaddy共享托管服务器上返回空字符串_Php_Git_Github_Ssh - Fatal编程技术网

Php shell_exec(';哪个git';)在Godaddy共享托管服务器上返回空字符串

Php shell_exec(';哪个git';)在Godaddy共享托管服务器上返回空字符串,php,git,github,ssh,Php,Git,Github,Ssh,我已经用git和我的服务器(godaddy共享主机)设置了关于SSH密钥的所有内容,并且可以通过SSH使用git pull成功地更新服务器git@github.com:username/reponame.git 当我提交对git repo的更改时,我试图使用自动更新测试服务器 当下面的php脚本摘录运行shell_exec('which git')时,函数返回一个空字符串 因为我可以在SSH中运行git命令,所以我觉得这一定是权限问题 我尝试运行chmod 755 foldertoupdate,

我已经用git和我的服务器(godaddy共享主机)设置了关于SSH密钥的所有内容,并且可以通过SSH使用
git pull成功地更新服务器git@github.com:username/reponame.git

当我提交对git repo的更改时,我试图使用自动更新测试服务器

当下面的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]
        );
    }
}
//检查所需的程序是否可用
$requiredBinaries=array('git','rsync');
//.....
foreach($requiredBinaries as$command){
$path=trim(shell_exec('which'.$command));
如果($path=''){
die(sprintf(“%s不可用。需要在服务器上安装它才能使此脚本正常工作。
输出为:%s',$command,$path));//此检查在第一个元素“git”上失败,该元素声称未安装git }否则{ $version=explode(“\n”,shell_exec($command.--version”); printf(“%s:%s”。“\n” ,$path ,$version[0] ); } }
更多信息:
  • 我正在更新的文件夹位于
    ~/html/TeamBoard
  • 我调用代码的文件位于
    ~/html/TeamBoard/deploy.php

Godaddy技术支持确认
php
在其共享托管环境中无权访问
git
命令。他们说需要VPS来实现这一点。

正如我所看到的,这不是从代码中执行git,而是执行shell程序(
,在本例中为
)。不清楚您是通过浏览器还是直接在shell中执行deploy.php脚本


尝试使用exec('command-vgit',$output,$retval)
检查PHP交互模式下的
git
命令可用性(
PHP-a
),看看这是否有效。

脚本是从哪个目录运行的,您是否能够从该位置成功发出命令行git命令?@TimBiegeleisen PHP文件位于我希望更新的文件夹中,
~/html/TeamBoard
是文件夹,文件位于
~/html/TeamBoard/deploy.php
。当
cd
进入
html
文件夹时,我能够很好地将repo克隆到此文件夹,但现在我尝试执行
git pull
操作,我得到了您从远程文件夹中提取的请求git@github.com:DelightedD0D/TeamBoard.git',但未指定分支。因为这不是当前分支的默认远程配置,所以必须在命令行上指定分支。apache用户(或php在浏览器中运行的任何用户)需要相关文件夹的权限/binaries@Anthony你能告诉我怎么改变吗?我原以为
chmod 755 foldertoupdate
会起作用,但事实并非如此。我是否需要设置对实际安装git的文件夹的访问权限?我不确定,但请记住,如果apache在共享环境中运行,使其正常工作将使托管在同一个box上的任何其他站点能够在您的repo文件夹上执行git命令。也许可以看看在浏览器中运行的suphp?deploy.php之类的东西。其想法是让github的webhook特性在repo上运行提交时触发脚本来更新服务器。我添加了
exec('command-vgit',$output,$retval);echo$retval
在文件中,但它也回显一个空字符串,因此似乎是不允许的。