Skip to main content
📝 Aplicações Laravel

How to Deploy Laravel Projects to Production Automatically Using GitHub Actions

Automate Laravel deployments to production with GitHub Actions. Complete CI/CD pipeline setup — from push to live in minutes, zero manual steps.

3 min

Tempo de leitura

599

Palavras

Apr 13, 2025

Publicado

Engr Mejba Ahmed

Escrito por

Engr Mejba Ahmed

Compartilhar Artigo

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 "[email protected]"

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.

Coffee cup

Gostou deste artigo?

Seu apoio me ajuda a criar mais conteúdo técnico aprofundado, ferramentas open-source e recursos gratuitos para a comunidade de desenvolvedores.

Tópicos Relacionados

Engr Mejba Ahmed

Sobre o Autor

Engr Mejba Ahmed

Engr. Mejba Ahmed builds AI-powered applications and secure cloud systems for businesses worldwide. With 10+ years shipping production software in Laravel, Python, and AWS, he's helped companies automate workflows, reduce infrastructure costs, and scale without security headaches. He writes about practical AI integration, cloud architecture, and developer productivity.

Discussion

Comments

0

No comments yet

Be the first to share your thoughts

Leave a Comment

Your email won't be published

6  x  6  =  ?

Continue Aprendendo

Artigos Relacionados

Ver Todos

Comments

Leave a Comment

Comments are moderated before appearing.

Learning Resources

Expand Your Knowledge

Accelerate your growth with structured courses, verified certificates, interactive flashcards, and production-ready AI agent skills.

Sample Certificate of Completion

Sample certificate — complete any course to earn yours

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support