Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zero-24/php-gitdeploy-script
Automatically deploy code using PHP and Git.
https://github.com/zero-24/php-gitdeploy-script
deployment git git-webhook php
Last synced: 6 days ago
JSON representation
Automatically deploy code using PHP and Git.
- Host: GitHub
- URL: https://github.com/zero-24/php-gitdeploy-script
- Owner: zero-24
- License: mit
- Created: 2024-07-30T17:51:49.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-08-06T15:11:02.000Z (3 months ago)
- Last Synced: 2024-08-06T17:55:11.296Z (3 months ago)
- Topics: deployment, git, git-webhook, php
- Language: PHP
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-gitdeploy-script
_Automatically deploy code using PHP and Git._This script is largly based on [https://github.com/markomarkovic/simple-php-git-deploy/tree/1.3.1](markomarkovic/simple-php-git-deploy) version 1.3.1 but modified for my usecases
## Requirements
* `git` and `rsync` are required on the server that's running the script
(_server machine_).
- Optionally, `tar` is required for backup functionality (`BACKUP_DIR` option).
- Optionally, `composer` is required for composer functionality (`USE_COMPOSER`
option).
* The system user running PHP (e.g. `www-data`) needs to have the necessary
access permissions for the `TMP_DIR` and `TARGET_DIR` locations 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 to access the remote repository.## Usage
* Configure the script and put it somewhere that's accessible from the
Internet. The preferred way to configure it is to use `deploy-config.php` file.
Rename `deploy-config.example.php` to `deploy-config.php` and edit the
configuration options there. That way, you won't have to edit the configuration
again if you download the new version of `deploy.php`.
* Configure your git repository to call this script when the code is updated.
The instructions for GitHub and Bitbucket are below.### GitHub
- _(This step is only needed for private repositories)_ Go to
`https://github.com/USERNAME/REPOSITORY/settings/keys` and add your server
SSH key.
- Go to `https://github.com/USERNAME/REPOSITORY/settings/hooks`.
- Click **Add webhook** in the **Webhooks** panel.
- Enter the **Payload URL** for your deployment script e.g. `https://example.com/deploy.php`.
- Configure the option **Content type** with `application/x-www-from-urlencoded`.
- Add the value from `SECRET_ACCESS_TOKEN` as to the field **Secret**.
- _Optional_ Choose which events should trigger the deployment usually thats just `push`.
- Make sure that the **Active** checkbox is checked.
- Click **Add webhook**.## 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
* Because `rsync` is used for deployment, the `TARGET_DIR` doesn't have to be
on the same server that the script is running e.g. `define('TARGET_DIR',
'[email protected]:/full/path/to/target_dir/');` is going to work as long
as the user has the right SSH keys and access permissions.
* You can have multiple scripts with different configurations. Simply rename
the `deploy.php` to something else, for example `deploy_master.php` and
`deploy_develop.php` and configure them separately. In that case, the
configuration files need to be named `deploy_master-config.php` and
`deploy_develop-config.php` respectively.