Skip to content

Instantly share code, notes, and snippets.

@tarikmanoar
Last active April 9, 2025 03:34
Show Gist options
  • Save tarikmanoar/b1d8a0b51d19851c975166a7d468f421 to your computer and use it in GitHub Desktop.
Save tarikmanoar/b1d8a0b51d19851c975166a7d468f421 to your computer and use it in GitHub Desktop.
This gist help you to deploy laravel application from github to your server using ssh
name: πŸŽ‰ Laravel Deploy
on:
push:
branches: [master]
workflow_dispatch: # Allow manual triggering
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.3'
extensions: mbstring, xml, ctype, iconv, intl, pdo_mysql, bcmath, zip, curl, fileinfo, tokenizer, dom, json, exif, gd, imagick, mysqli, redis, sodium, pgsql, sqlite3
coverage: none
- name: 🧰 Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'npm'
- name: ♻️ Cache Composer dependencies
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: 🧩 Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
- name: Run PHP Code Style (Pint)
run: vendor/bin/pint
- name: ♻️ Cache NPM dependencies
id: npm-cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-
- name: πŸ“₯ Install NPM dependencies
run: npm ci
- name: πŸ”¨ Build frontend assets
run: npm run build
- name: πŸš€ Upload to server via SCP
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
password: ${{ secrets.PASSWORD }}
source: ".,!.git,!.github,!node_modules,!tests,!storage/framework/testing,!.env,!.vscode,!.idea"
target: ${{ secrets.DIR }}
strip_components: 0
- name: πŸ› οΈ Run deployment commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
password: ${{ secrets.PASSWORD }}
script: |
cd ${{ secrets.DIR }}
php artisan down --retry=60
php artisan migrate --force
php artisan optimize:clear
php artisan optimize
php artisan storage:link
# Verify deployment succeeded
if php artisan --version > /dev/null; then
php artisan up
echo "Deployment successful!"
else
echo "Deployment failed, site remains in maintenance mode"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment