How to Deploy Laravel Projects to Production Automatically Using GitHub Actions

Laravel Applications Apr 13, 2025 Engr Mejba Ahmed 3 min read
๐Ÿ“š Table of Contents
How to Deploy Laravel Projects to Production Automatically Using GitHub Actions

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:

  • Automate your production deployment after every push.
  • Avoid using insecure FTP tools.
  • Save time and reduce human error.
  • Build a proper CI/CD pipeline as a Laravel developer.

๐Ÿง  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:

  • ~/.ssh/colorpark_hostinger (private key)
  • ~/.ssh/colorpark_hostinger.pub (public key)
  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

  • Make sure your server has proper file permissions.
  • Always back up your .env and database before running php artisan migrate --force.
  • If using shared hosting, confirm if it supports SSH key login and composer.

๐Ÿ“Œ 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.

Share this post

Engr Mejba Ahmed

About the Author: Engr Mejba Ahmed

I'm Engr. Mejba Ahmed, a Software Engineer, Cybersecurity Engineer, and Cloud DevOps Engineer specializing in Laravel, Python, WordPress, cybersecurity, and cloud infrastructure. Passionate about innovation, AI, and automation.