Search code examples
gitgithubhostinglampbitbucket

Git workflow from local to bitbucket/github hub to live webserver


I would like to setup a workflow that enables pushing local changes to Bitbucket or Github (but ideally the former) that then updates a live site hosted on my lamp VPS server. Is this possible? I remember working some time ago with a team that had a similar setup but with Github.

There is an article by Joe Maller http://joemaller.com/990/a-web-focused-git-workflow/ that describes a similar approach where the hub is another directory on the same webserver.


Solution

  • That kind of post-push action is managed:

    In both cases, those hooks generate a POST hook which passes a payload to your third-party web application through its API.
    Your third-party application is responsible for receiving and transforming the payload.

    That means your lamp VPS server needs to have a listener in place able to interpret said payload.
    you can see an example of a script managing a deployment in this article, by doing a git pull:

         // Make sure we're in the right directory
          exec('cd '.$this->_directory, $output);
          $this->log('Changing working directory... '.implode(' ', $output));
    
          // Discard any changes to tracked files since our last deploy
          exec('git reset --hard HEAD', $output);
          $this->log('Reseting repository... '.implode(' ', $output));
    
          // Update the local repository
          exec('git pull '.$this->_remote.' '.$this->_branch, $output);
          $this->log('Pulling in changes... '.implode(' ', $output));