Skip to content

Instantly share code, notes, and snippets.

@Shaz3e
Last active November 27, 2024 22:47
Show Gist options
  • Save Shaz3e/58c9e0b87fd766c36de34a120633ea2c to your computer and use it in GitHub Desktop.
Save Shaz3e/58c9e0b87fd766c36de34a120633ea2c to your computer and use it in GitHub Desktop.
Connect Private Repo

Pull github respository into cpanel and auto deploy recent chagnes

First check at cPanel SSH Access there should not be any key if there is any delete this than generate new key from terminal ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa

After generating key Go to .ssh directory and open .pub file and copy SSH Key Add this SSH Key into GITHUB REPO - Setting - Deploy Keys

Backup all files from public_html to _backup directory e.g. /home/_backup Open Git Version Control and Copy SSH GIT URL and Update Repository Directory path should /public_html Move Backup files into public_html

After moving files to go public_html/.git/hooks/post-receive

Update the following code make sure use your branch name e.g. master or main and edit /home/username/public_html or /home1/username/public_html

#!/bin/sh GIT_WORK_TREE=/home/username/public_html git checkout -f master cd /home/username/public_html

Pull the latest changes

git pull origin master

Update Composer dependencies

composer install --no-dev --optimize-autoloader

Run database migrations and clear optimizations

php artisan migrate --force php artisan optimize:clear

Open Terminal again and check git connection

ssh -T git@github.com If success message appears means you are connected git repo via ssh connection

Than type cd public_html/.git/hooks chmod +x post-receive

Update cron job cd /home/username/public_html && git pull origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment