Automatic deployment for web-based projects

Based on «Automated git deployment» script by Jonathan Nicoal. See also BitBucket Sync by alixandru.

Some fragments of this manual was taken from Jonathan Nicoal's documentation page.

Version 0.0.3 Last changes 2016.03.25

Documentation is in progress.


  • Fixed new webhooks interface (stream instead of POST). See discussion on another synchronizator bitbucket-sync by alixandru.
  • Added support for multiple projects. See array $PROJECTS in config.sample.php.
  • Optional fetching or cloning repositiories demand on their presence.
  • Project and repository folders automaticly creating if they're not exists. (You need no to create empty folders before operations and can to reset and initiate full reload by simply removing entire repository/project folders.)
  • Post hook command execution.


  • PHP 5.3+;
  • Git installed;
  • Shell access;
  • PHP exec function;
  • SSH key pair for bitbucket created with empty passphrase;


For your server to connect securely to Bitbucket without a password prompt, it needs to use an SSH key.

On your server navigate to the ~/.ssh directory of the user that PHP runs under. You will need to create the user's .ssh directory if it doesn't exist. At a shell prompt type:

cd ~/.ssh
ssh-keygen -t rsa

When prompted either accept the default key name (id_rsa) or give your key a unique name. Press enter when asked for a passphrase, which will generate a passwordless key. Usually this isn't recommended, but we need our script to be able to connect to Bitbucket without a passphrase.

A public and private key pair will be generated. Copy your public key — the one with a .pub extension — to the clipboard. On the Bitbucket website navigate to Account > SSH Keys, and choose to add a new key. Paste in your public key and save it.

Back on your server, edit your ~/.ssh/config file to add as a host. This ensures that the correct key is used when connecting by SSH to You'll need to create the config file if it doesn't exist:

    IdentityFile ~/.ssh/bitbucket_rsa

Whenever you do a git fetch Bitbucket will verify your identity automatically, without prompting you for a password.

On the Bitbucket website navigate to your repository's Administration > Webhooks screen and add a new webhook, pointed to http://<domain>/<path>/bitbucket-hook.php.

For more detailed information see the original Jonathan's page, look config file and source code or simply ask me.


2016.03.25, v.0.0.3

2015.10.05, v.0.0.2

  • Added project parameter for post deploy execution: $PROJECTS['repo-name']['postHookCmd'] (see config.sample.php). For example, touch index.wsgi for django configuration reloading: ... 'postHookCmd' => 'touch index.wsgi', .... Command running in project folder (specified by deployPath parameter.