A PHP script to automatically pull from a repository to a web server (using a webhook on GitHub, GitLab, or Bitbucket).
You can configure which branch this script pulls from. This script is useful for both development and production servers.
Generate an SSH key and add it to your account so that git pull
can be run without a password.
Copy the git-deploy folder and its contents in to your public folder (typically public_html). Note that you can change the name of the folder if desired.
Rename git-deploy/config.sample.php to git-deploy/config.php, and update each variable.
define('TOKEN', 'your-secret-token');
define('REMOTE_REPOSITORY', 'your-repository');
define('DIR','your-absolute-path-to-git');
define('AFTER_PULL','your-shell-commands');
In your repository, navigate to Settings → Webhooks → Add webhook, and use the following settings:
- Payload URL: https://www.yoursite.com/git-deploy/deploy.php?token=your-secret-token
- Content type: application/json
- Secret: blank (this script uses a token at the end of the URL as the secret)
- Which events would you like to trigger this webhook?: 🔘 Just the push event
- Active: ☑️
Click "Add webhook" to save your settings, and the script should start working.
In your repository, navigate to Settings → Integrations, and use the following settings:
- URL: https://www.yoursite.com/git-deploy/deploy.php?token=your-secret-token
- Secret Token: blank (this script uses a token at the end of the URL as the secret token)
- Trigger: ☑️ Push events
- Enable SSL verification: ☑️ (only if using SSL, see GitLab's documentation for more details)
Click "Add webhook" to save your settings, and the script should start working.
In your repository, navigate to Settings → Webhooks → Add webhook, and use the following settings:
- Title: git-deploy
- URL: https://www.yoursite.com/git-deploy/deploy.php?token=your-secret-token
- Active: ☑️
- SSL / TLS: ⬜ Skip certificate verification (only if using SSL, see Bitbucket's documentation for more details)
- Triggers: 🔘 Repository push
Click "Save" to save your settings, and the script should start working.
Hey dude! Help me out by buying me a couple of 🍻!