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:
- A Laravel project hosted on GitHub.
- A Hostinger VPS or Web Hosting plan with SSH access.
- Access to the terminal/command line.
- Composer installed on your server.
π οΈ Step 1: Generate SSH Key and Upload to Hostinger
- 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)
- 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
- 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 runningphp 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.