Skip to content

Instantly share code, notes, and snippets.

@ericamigo
Last active May 24, 2025 06:34
Show Gist options
  • Save ericamigo/679dd743e11b08c550fcd84acf4c2eaf to your computer and use it in GitHub Desktop.
Save ericamigo/679dd743e11b08c550fcd84acf4c2eaf to your computer and use it in GitHub Desktop.
setup github actions
name: Deploy Laravel Application to Production Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
- name: Install Composer Dependencies
run: composer install --optimize-autoloader --no-dev --no-progress --no-interaction --prefer-dist
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install NPM Dependencies
run: npm install
- name: Build NPM Assets
env:
VITE_PUSHER_APP_KEY: ${{ secrets.VITE_PUSHER_APP_KEY }}
VITE_PUSHER_PORT: ${{ secrets.VITE_PUSHER_PORT }}
VITE_PUSHER_SCHEME: ${{ secrets.VITE_PUSHER_SCHEME }}
VITE_PUSHER_APP_CLUSTER: ${{ secrets.VITE_PUSHER_APP_CLUSTER }}
run: npm run build
- name: Synchronize Files To Production
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SOURCE: '.'
REMOTE_HOST: ${{ secrets.VPS_HOST }}
REMOTE_USER: ${{ secrets.VPS_USER }}
TARGET: '/var/www/project-folder'
- name: Run Remote/Artisan Commands
uses: appleboy/[email protected]
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/project-folder
php artisan migrate --force
php artisan db:seed --class=MenuItemSeeder --force
php artisan cache:clear
php artisan optimize

setup local ssh

  1. cd ~/.ssh
  2. ssh-keygen -t ecdsa -b 521 key starts with id_
  3. ssh-copy-id username@ip
  4. setup github action secrets. cat id_* then copy the private key
  5. copy the build.yml to your /.github/workflows folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment