webforward / gitdeploy
Easy to use automatic git deployment for PHP projects with composer and npm support
Installs: 25
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/webforward/gitdeploy
Requires
- php: >=7.0
This package is auto-updated.
Last update: 2025-10-29 02:37:21 UTC
README
Easy to use automatic git deployment for PHP projects with composer and npm support.
Requirements
- PHP 7.0 or above with
proc_openandshell_execfunctions enabled. gitandrsyncare required on the server that's running the script (server machine).- Optionally,
taris required for backup functionality (backup_diroption). - Optionally,
composeris required for composer functionality (use_composeroption). - Optionally,
npmis required for composer functionality (use_npmoption).
- Optionally,
- The system user running PHP (e.g.
www-data) needs to have the necessary access permissions for thetemp_dirandtarget_dirlocations on the server machine. - If the Git repository you wish to deploy is private, the system user running PHP also needs to have the right SSH keys installed to access the remote repository. See GitHub or BitBucket for examples.
Usage - In your own project though composer
- Start by running the command
composer require webforward/gitdeploy:dev-master. - Use the following code in your project and configure options:
use GitDeploy\GitDeploy; // PSR-4 - This line must be at the top of a script, not inside a function $gd = new GitDeploy(); $gd->remote_repository = 'https://github.com/williammalone/Simple-HTML5-Drawing-App.git'; $gd->target_dir = '/home/user/public_html'; // Your configurable options here, see deploy.php $gd->deploy();
- Setup a check/method in which the above code is not publicly accessible by anyone,
the code should be placed behind an admin php session, or the requirement
to enter a secret key or password to run the deploy() function. Check
deploy.phpfor an easy method of how this can be implemented. - Make sure these files also exist within your git repository else (depending on your configured options) they could be removed on the next deployment.
- Test the deployment by visiting the script url in your browser.
- Once happy, follow the steps of setting up a hook. See GitHub, BitBucket or Generic Git for examples.
Usage - Standalone
- Download a copy of this repository into a directory within your website, for example /deploy.
- Edit
deploy.phpor make your own php file and use the following code with configure options:
use GitDeploy\GitDeploy; // This line must be at the top of a script, not inside a function require 'path/to/src/GitDeploy.php'; $gd = new GitDeploy(); $gd->remote_repository = 'https://github.com/williammalone/Simple-HTML5-Drawing-App.git'; $gd->target_dir = '/home/user/public_html'; // Your configurable options here, see deploy.php $gd->deploy();
- Setup a check/method in which the above code is not publicly accessible by anyone,
you can use the example already written in
deploy.php. For security reasons, your script should require the input of a secret key or password to run the deploy() function. - Make sure these files also exist within your git repository else (depending on your configured options) they could be removed on the next deployment.
- Test the deployment by visiting the script url in your browser.
- Once happy, follow the steps of setting up a hook. See GitHub, BitBucket or Generic Git for examples.
GitHub
- (This step is only needed for private repositories) Go to
https://github.com/USERNAME/REPOSITORY/settings/keysand add your server SSH key. - Go to
https://github.com/USERNAME/REPOSITORY/settings/hooks. - Click Add webhook in the Webhooks panel.
- Enter the URL for your deployment script e.g.
https://domain.com/deploy.php?secret=changeme. - Optional Choose which events should trigger the deployment.
- Make sure that the Active checkbox is checked.
- Click Add webhook.
Bitbucket
- (This step is only needed for private repositories) Go to
https://bitbucket.org/USERNAME/REPOSITORY/admin/deploy-keysand add your server SSH key. - Go to
https://bitbucket.org/USERNAME/REPOSITORY/admin/services. - Add POST service.
- Enter the URL to your deployment script e.g.
https://domain.com/deploy.php?secret=changeme. - Click Save.
Generic Git
- Configure the SSH keys.
- Add an executable
.git/hooks/post_receivescript that calls the script e.g.
#!/bin/sh wget -q -O /dev/null https://domain.com/deploy.php?sat=changeme
You're 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 and src/GitDeploy.php.
If you find this script useful, consider donating to PayPal richard@webfwd.co.uk.