Git lets you deploy code changes by pushing from your local machine directly to your server.
mkdir ~/repos/mysite.git
cd ~/repos/mysite.git
git init --bare
nano ~/repos/mysite.git/hooks/post-receive
Add:
#!/bin/bash
GIT_WORK_TREE=~/public_html git checkout -f
echo "Deployed successfully!"
Make it executable:
chmod +x ~/repos/mysite.git/hooks/post-receive
git remote add production ssh://yourusername@your-domain.com/~/repos/mysite.git
git push production main
Your files are automatically deployed to ~/public_html/.
For automated deployments on push to GitHub:
.github/workflows/deploy.yml:name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd ~/public_html
git pull origin main
composer install --no-dev