2

I have everything setup with git and my server (godaddy shared hosting) regarding SSH keys and can update the server successfully via SSH with git pull git@github.com:username/reponame.git

I'm attempting to use simple-php-git-deploy to automatically update a test server when I commit changes to my git repo

When the below php script excerpt runs shell_exec('which git') the function returns an empty string.

Since I can run git commands in SSH, I feel like this must be a permissions issue.

I tried running chmod 755 foldertoupdate with no change.

What do I need to do to allow php (or the current apache user) to call git commands?

// 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]
        );
    }
}

More Info:

  • The folder I'm updating is at ~/html/TeamBoard
  • The file I'm calling the code from is at ~/html/TeamBoard/deploy.php
Community
  • 1
  • 1
Wesley Smith
  • 19,401
  • 22
  • 85
  • 133
  • From which directory is your script running, and have you been able to successfully issue a command line git command from this location? – Tim Biegeleisen May 18 '15 at 05:02
  • @TimBiegeleisen The php file is in the folder I wish to update, `~/html/TeamBoard` is the folder and and the file is at `~/html/TeamBoard/deploy.php`. I was able to clone the repo to this folder fine while `cd` into the `html` folder but now that I try to do `git pull` I get You asked to pull from the remote 'git@github.com:DelightedD0D/TeamBoard.git', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line. – Wesley Smith May 18 '15 at 05:10
  • The apache user (or whichever user php runs as in browser) needs permission to the relevant folders/binaries – Anthony May 18 '15 at 05:26
  • @Anthony Can you tell me how to change that? I thought `chmod 755 foldertoupdate` would work but it did not. Do I need to set the access for the folder where git is actually installed? – Wesley Smith May 18 '15 at 05:28
  • I'm not sure, but keep in mind that if apache is running in shared environment, getting this to work would give any other sites hosted on same box ability to execute git commands on your repo folder. Maybe look at something like suphp? – Anthony May 18 '15 at 05:50

2 Answers2

1

Godaddy tech support confirmed that php does not have access to git commands in their shared hosting environment. They said that VPS would be needed to achieve this.

Wesley Smith
  • 19,401
  • 22
  • 85
  • 133
1

As I can see, it's not about executing git from your code, but about executing shell programs (which, in this case). It is not clear if you are executing the deploy.php script via a browser or directly in the shell.

Try to use exec('command -v git', $output, $retval); to check git command availability in PHP interactive mode (php -a) and see if this works there.

adriann
  • 396
  • 2
  • 12
  • deploy.php is being run in a browser. The idea is to have github's webhook feature trigger the script to update the server when a commit is run on the repo. I added `exec('command -v git', $output, $retval); echo $retval;` in the file but it echos an empty string as well so seems like a no go. – Wesley Smith May 18 '15 at 11:19