https://github.com/chriscarini/init-github-to-remote-host-php-git-deploy
Initialize a GitHub repo to deploy on a remote host using a Simple PHP Git deploy script
https://github.com/chriscarini/init-github-to-remote-host-php-git-deploy
Last synced: about 2 months ago
JSON representation
Initialize a GitHub repo to deploy on a remote host using a Simple PHP Git deploy script
- Host: GitHub
- URL: https://github.com/chriscarini/init-github-to-remote-host-php-git-deploy
- Owner: ChrisCarini
- Created: 2020-11-08T05:03:54.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-08T05:08:22.000Z (almost 5 years ago)
- Last Synced: 2025-06-03T00:37:37.557Z (4 months ago)
- Language: Shell
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Initialize a new GitHub repo to deploy changes to a remote host
This repository provides directions (and, better yet, a quick script) on how to create and configure a
new GitHub repository to sync / deploy changes to a remote host.We leverage [markomarkovic/simple-php-git-deploy](https://github.com/markomarkovic/simple-php-git-deploy) for the php/git deploy hooks.
## Pre-req
You need to have:
1) **A HTTPS domain already created on your hosting provider** -
subdomains ok; the webserver document root for the domain should exist off of the users home directory;
the document root can have contents, we will attempt to back them up locally and remotely.
**Example:**
- `https:///` should load.
- `~/` should exist on your remote host. If files already exist in this directory, the
`install.sh` script will back them up on the remote host, and make them part of the initial commit to
the GitHub repo.1) **SSH access to your hosting provider**
**Example:** You should be able to `ssh` to ``.
1) **An empty GitHub repo** - the repo name should match the name of the (sub)domain.
**Example:** `https://github.com//` should exist and be empty.## Quick Script
Change directories to where you want your GitHub repo to be initialized locally, and run the `install.sh`
script found in this directory.Try to use the script instead of the manual steps below - automation is nice.
## Manual Steps
1) Create new git repo on local machine (`git init`)
1) Copy any existing files from your remote host into the new git repo you just created above
1) Add the submodule php git deploy hooks (`git submodule add https://github.com/markomarkovic/simple-php-git-deploy.git deploy-hooks`)
1) Create a *strong* `SECRET_ACCESS_TOKEN` (`sed "s/[^a-zA-Z0-9]//g" <<<$(openssl rand -base64 128) | head -c 65`)
1) Create the `deploy-hooks/deploy-config.php` file (see `deploy-config.example.php` for full docs) - use the `SECRET_ACCESS_TOKEN` created above
1) Create reasonable `.gitignore` and `.htaccess` files; examples below:
### `.gitignore`
```
.idea/
VERSION
**/deploy-config.php
```
### `.htaccess`
```
Options -Indexes
RewriteEngine On
# Force site to redirect to HTTPS instead of HTTP
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Return 404 for certain files/directories
RedirectMatch 404 /\.git
RedirectMatch 404 \.gitignore
RedirectMatch 404 \.gitmodules
RedirectMatch 404 README\.md
RedirectMatch 404 VERSION
```
1) Add all the files, and push your code (`git add ./ && git commit && git push -u origin main`)
1) Configure a webhook at `https://github.com///settings/hooks`
1) **Payload URL:** `https:///deploy-hooks/deploy.php?sat=`
1) **Content Type:** `application/x-www-form-urlencoded`
1) **Secret:** *EMPTY*
1) **SSL verification:** `Enable SSL Verification`
1) **Which events would you like to trigger this webhook?:** `Just the push event`
1) **Active:** *Check*
1) SSH to your remote host, and checkout your repo (use the `git clone --recurse-submodules git@github.com:/.git ~/`)
1) Copy the `deploy-hooks/deploy-config.php` you created above over to your remote host directory `~//deploy-hooks/deploy-config.php`
1) Create the `~/_backups` on your remote host
1) Profit.You should now be able to push commits to this git repo and have your domain automatically pull the changes.