Download the PHP package tmd/auto-git-pull without Composer
On this page you can find all versions of the php package tmd/auto-git-pull. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tmd/auto-git-pull
More information about tmd/auto-git-pull
Files in tmd/auto-git-pull
Package auto-git-pull
Short Description Automatically pulls a git repository when commits are pushed.
License MIT
Informations about the package auto-git-pull
Auto git pull
Automatically pull when changes are pushed to a Git repository.
(Actually it does a git fetch
followed by git reset
but that wasn't as catchy.)
About
There are two important parts:
- A PHP script which Bitbucket or GitHub will automatically send a request to when you push. (
http://mysite/deploy.php
in the examples below) - A shell script which does the actual pulling. (
scripts/git-pull.sh
)
The reason for the separation is so you don't need to grant the web user write permission to your files. You just need to allow it to run the one script as a user that does have write permission.
Setup
-
Install the latest version with
composer require tmd/auto-git-pull
- Make the pull script executable (you need to do this if you update the package as well):
You can have this automatically happen by adding this to your composer.json
:
- Create a publicly accessible URL on your site which will be called by GitHub/Bitbucket and run the deployment (e.g.
http://mysite.com/deploy.php
) and set the parameters as appropriate.
Example showing all the options that can be given and their default values:
The only required option is directory
Example in Laravel showing minimal options:
Example with logging:
- Add the hook on Bitbucket/GitHub to run the script:
If the web server user does not have write permissions on the directory
If your webserver runs as a different user than the owner of the files (as is best practise) you need to allow the webserver to do the pull.
-
Allow the web server user to run the pull script as a user with write permissions:
- Set the user to run the pull as in the parameters:
If your repository is private
You need to setup a deployment key so the pull can happen without a password being entered.
-
Generate an sshkey using
ssh-keygen
*for the user that will run the pull script (e.g.www-data
). - Follow these instructions to add a deployment key to the git repository:
Bitbucket: https://confluence.atlassian.com/bitbucket/use-deployment-keys-294486051.html GitHub: https://developer.github.com/guides/managing-deploy-keys/#deploy-keys
- Change your git remote url from HTTPS to SSH if necessary:
If your output looks like this, you're using HTTPS:
Change it to use ssh, like this: