V
V
Vladislav2015-11-20 11:19:08
PHP
Vladislav, 2015-11-20 11:19:08

How to git pull origin master from php?

There is a repository on bitbucket, when a push is made there, a hook is triggered and a request is sent to the combat server that launches the deploy script. This script should pull from the repository. But for some reason he does not do it, he does not display any errors. The repository is accessed via ssh, all the necessary keys are there, you don’t need to do ssh-add, since everything is set to automatically add there, etc. The rights to the folder are, the owner is the same as running php. In short, everything is fine, and before get pull, I do git reset --hard HEAD and everything works fine. Here is the script itself:

<?php

/**
* 
*/
class Deploy implements DeployInterface
{
  private $payload;

  function __construct()
  {
    $this->payload = json_decode(file_get_contents('php://input'));
  }

  public function pull()
  {
    $output = '';
    if ($this->payload) {
      chdir('/var/www/'.$this->payload->repository->name);
      exec('git reset --hard HEAD', $output);
      file_put_contents('test.txt', $output, FILE_APPEND);
      exec('git pull origin master', $output);
      file_put_contents('test.txt', $output, FILE_APPEND);
    }
  }
}

What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2015-11-21
@MrBikus

In short, in the /var/www/ directory, you need to create a .ssh directory for the www-data user. Then create private and public keys. When creating keys, do not put a password on them. And everything will work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question