Are you tired of manually uploading your Laravel project to a production server every time you push new updates? In this guide, you'll learn how to automate your Laravel deployment process using GitHub Actions β€” the DevOps-friendly, CI/CD tool built into GitHub.

Let’s streamline your workflow and deploy your Laravel app to your Hostinger VPS (or any SSH-accessible server) with a single git push.

βœ… Why Use GitHub Actions for Laravel Deployment?

Using GitHub Actions allows you to:


🧠 Prerequisites

Before starting, make sure you have:

  1. A Laravel project hosted on GitHub.
  2. A Hostinger VPS or Web Hosting plan with SSH access.
  3. Access to the terminal/command line.
  4. Composer installed on your server.

πŸ› οΈ Step 1: Generate SSH Key and Upload to Hostinger

  1. Generate SSH Key on your local machine:
ssh-keygen -t rsa -b 4096 -C "github-actions@example.com"

It will generate two files:

  1. Add the public key to Hostinger:

Go to Hostinger β†’ Advanced β†’ SSH Access β†’ SSH Keys
Click Add SSH Key, paste the public key content from:

cat ~/.ssh/colorpark_hostinger.pub
  1. Save the private key content to be added as a GitHub Secret later:
cat ~/.ssh/colorpark_hostinger

πŸ” Step 2: Add GitHub Secrets

In your GitHub repository:

Go to: Settings β†’ Secrets and variables β†’ Actions β†’ New repository secret

Add the following secrets:

HOSTINGER_SSH_HOST='145.223.89.199'      # Your server IP
HOSTINGER_SSH_PORT='65002'               # Your SSH port
HOSTINGER_SSH_USER='u597250090'          # Your SSH username
HOSTINGER_SSH_KEY='(paste your PRIVATE key content)'
DEPLOY_PATH='/home/u597250090/domains/example.com/public_html'

πŸ“ Step 3: Create GitHub Actions Workflow

Inside your Laravel project, create the following file:

mkdir -p .github/workflows
touch .github/workflows/deploy.yml

Paste the following complete deploy.yml config:

name: πŸš€ Deploy to Hostinger

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up SSH key
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.HOSTINGER_SSH_KEY }}" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -p ${{ secrets.HOSTINGER_SSH_PORT }} ${{ secrets.HOSTINGER_SSH_HOST }} >> ~/.ssh/known_hosts

      - name: Deploy via rsync
        run: |
          rsync -avz --delete \
            --exclude=".env" \
            --exclude=".gitignore" \
            -e "ssh -p ${{ secrets.HOSTINGER_SSH_PORT }}" \
            ./ ${{ secrets.HOSTINGER_SSH_USER }}@${{ secrets.HOSTINGER_SSH_HOST }}:${{ secrets.DEPLOY_PATH }}

      - name: Laravel post-deploy commands
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.HOSTINGER_SSH_HOST }}
          username: ${{ secrets.HOSTINGER_SSH_USER }}
          key: ${{ secrets.HOSTINGER_SSH_KEY }}
          port: ${{ secrets.HOSTINGER_SSH_PORT }}
          script: |
            cd ${{ secrets.DEPLOY_PATH }}
            composer install --no-dev --prefer-dist --no-interaction
            php artisan optimize:clear

πŸš€ Step 4: Push Your Code to Trigger Deployment

Once everything is set up, just push your Laravel project to the main branch:

git add .
git commit -m "πŸ”§ Configure GitHub Actions for auto deployment"
git push origin main

GitHub will automatically trigger the deployment. You can view the logs under the "Actions" tab of your GitHub repo.


βœ… Bonus Tips


πŸ“Œ Final Thoughts

By integrating GitHub Actions into your Laravel deployment process, you’re not just saving time β€” you’re building a professional workflow that scales.

No more manual uploads, no more FTP. Just push and deploy. πŸ”₯


Want to build more automation like this?

πŸ‘‰ Follow for more Laravel DevOps tricks and full-stack developer tutorials.