Home

Awesome

Simple PHP Git deploy script

Automatically deploy the code using PHP and Git.

Requirements

Usage

GitHub

  1. (This step is only needed for private repositories) Go to https://github.com/USERNAME/REPOSITORY/settings/keys and add your server SSH key.
  2. Go to https://github.com/USERNAME/REPOSITORY/settings/hooks.
  3. Click Add webhook in the Webhooks panel.
  4. Enter the Payload URL for your deployment script e.g. http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile.
  5. Optional Choose which events should trigger the deployment.
  6. Make sure that the Active checkbox is checked.
  7. Click Add webhook.

Bitbucket

  1. (This step is only needed for private repositories) Go to https://bitbucket.org/USERNAME/REPOSITORY/admin/deploy-keys and add your server SSH key.
  2. Go to https://bitbucket.org/USERNAME/REPOSITORY/admin/services.
  3. Add POST service.
  4. Enter the URL to your deployment script e.g. http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile.
  5. Click Save.

Generic Git

  1. Configure the SSH keys.
  2. Add a executable .git/hooks/post_receive script that calls the script e.g.
#!/bin/sh
echo "Triggering the code deployment ..."
wget -q -O /dev/null http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile

Done!

Next time you push the code to the repository that has a hook enabled, it's going to trigger the deploy.php script which is going to pull the changes and update the code on the server machine.

For more info, read the source of deploy.php.

Tips'n'Tricks


If you find this script useful, consider donating BTC to 1fLnPZkMYw1TFNEsJZCciwDAmUhDw2wit.