Blog Web Development

How to Use GitHub Actions for CI/CD with Hostinger

A

Admin

Jan 1, 2026

4 min read 330 views

Introduction

Continuous Integration and Continuous Deployment (CI/CD) is essential for modern web development. In this comprehensive guide, we'll show you how to set up automated deployments from GitHub to Hostinger using GitHub Actions.

Why Use GitHub Actions for Deployment?

GitHub Actions offers several key advantages for automating your deployment workflow:

  • Automation: Deploy automatically when you push to your main branch
  • Consistency: Every deployment follows the same process
  • Time Savings: No more manual FTP uploads or SSH commands
  • Error Reduction: Automated processes minimize human error
  • Free for Public Repos: GitHub Actions is free for public repositories

Prerequisites

Before you begin, make sure you have:

  • A GitHub repository with your Laravel application
  • Hostinger hosting with SSH access enabled
  • Your SSH credentials (host, username, password, and port)
  • Git initialized on your Hostinger server

Step 1: Configure GitHub Secrets

GitHub Secrets allow you to store sensitive information securely. You'll need to add the following secrets to your repository:

  1. Navigate to your repository on GitHub
  2. Click SettingsSecrets and variablesActions
  3. Click New repository secret
  4. Add each of these secrets:
    • SSH_HOST: Your Hostinger server hostname
    • SSH_USERNAME: Your SSH username
    • SSH_PASSWORD: Your SSH password
    • SSH_PORT: SSH port (usually 22)
    • PROJECT_PATH: Full path to your project on the server

Step 2: Create the Workflow File

Create a new file at .github/workflows/deploy.yml in your repository:

name: Deploy to Hostinger

on:
  push:
    branches: [ main ]
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Deploy to Hostinger
      uses: appleboy/ssh-action@v1.0.3
      with:
        host: \${{ secrets.SSH_HOST }}
        username: \${{ secrets.SSH_USERNAME }}
        password: \${{ secrets.SSH_PASSWORD }}
        port: \${{ secrets.SSH_PORT }}
        script: |
          cd \${{ secrets.PROJECT_PATH }}

          echo "Pulling latest code..."
          git pull origin main

          echo "Installing PHP dependencies..."
          composer install --no-dev --optimize-autoloader

          echo "Building assets..."
          npm install
          npm run build

          echo "Running migrations..."
          php artisan migrate --force

          echo "Optimizing application..."
          php artisan config:cache
          php artisan route:cache
          php artisan view:cache
          php artisan optimize

          echo "Deployment completed!"

Step 3: Understanding the Workflow

Let's break down what this workflow does:

  • Trigger: Runs on every push to the main branch, or manually via workflow_dispatch
  • SSH Connection: Uses the appleboy/ssh-action to connect to your Hostinger server
  • Git Pull: Pulls the latest code from GitHub
  • Composer Install: Installs PHP dependencies in production mode
  • Asset Building: Runs npm install and builds your frontend assets
  • Database Migration: Runs Laravel migrations with --force flag
  • Cache Optimization: Caches config, routes, and views for better performance

Step 4: First-Time Server Setup

Before your first deployment, SSH into your Hostinger server and set up Git:

ssh your-username@your-server.com

cd /home/your-username/public_html

# Initialize Git repository
git init

# Add your GitHub repository as remote
git remote add origin https://github.com/your-username/your-repo.git

# Pull the initial code
git pull origin main

# Install dependencies
composer install --no-dev
npm install && npm run build

# Run migrations
php artisan migrate --force

# Set correct permissions
chmod -R 775 storage
chmod -R 775 bootstrap/cache

Step 5: Deploy and Monitor

Once everything is configured:

  1. Commit your workflow file: git add .github/workflows/deploy.yml && git commit -m "Add deployment workflow"
  2. Push to GitHub: git push origin main
  3. Go to the Actions tab in your GitHub repository
  4. Watch your deployment in real-time
  5. Check your website to verify the deployment was successful

Troubleshooting Common Issues

Permission Denied Errors: Verify your SSH credentials are correct in GitHub Secrets.

Composer/NPM Not Found: Ensure these tools are installed on your Hostinger server.

Git Pull Fails: Check that Git is properly initialized and the remote is configured.

Best Practices

  • Always test deployments in a staging environment first
  • Use environment-specific .env files for different configurations
  • Keep your GitHub Secrets secure and rotate them periodically
  • Monitor deployment logs for any warnings or errors
  • Consider adding automated tests before deployment

Conclusion

Automating your deployment workflow with GitHub Actions saves time, reduces errors, and allows you to focus on writing code instead of managing deployments. With this setup, every push to your main branch automatically deploys to production, giving you a professional CI/CD pipeline.

At CarrotSoft, we use this exact workflow for all our Laravel projects, and it's proven to be reliable and efficient. If you need help setting up automated deployments for your project, get in touch with us!

Tags:

#Laravel #Tutorial #Best Practices

Share this article:

Related Articles

Ready to Start Your Project?

Let's turn your ideas into reality. Get in touch with our team today.

Get Started