Hostinger Deploy Skill
One-command deployment from a local dist/ folder to Hostinger shared hosting via rsync over SSH. Handles SPA routing, incremental pushes, and rollback. Works with React, Vite, Next.js (static export), Astro, or any static/SPA build.
What It Does
- Runs
npm run buildlocally - Rsyncs
dist/to Hostinger web root (incremental, skips unchanged files) - Injects/updates
.htaccessfor SPA routing (RewriteRule . /index.html [L]) - Works with any React/Vite/Next.js/Astro static export
- Single config section at the top of the script
Prerequisites
rsyncinstalled locally (brew install rsync/apt install rsync)- SSH key access to your Hostinger account
- Your site builds to a
dist/directory
Setup
1. Add SSH key to Hostinger
In Hostinger hPanel → SSH Access → Add your public key:
cat ~/.ssh/id_ed25519.pub
# or
cat ~/.ssh/id_rsa.pub
If you don't have an SSH key yet:
ssh-keygen -t ed25519 -C "your_email@example.com"
2. Configure the script
Edit the top config section of scripts/deploy.sh:
HOST="u528135200@your-username.your-domain.com" # SSH host (username@domain)
PORT="22" # SSH port (22 = standard, 65002 = some Hostinger accounts)
DEST="/home/username/domains/your-domain.com/public_html" # Hostinger web root
DIST="dist" # Your build output directory
Finding your web root: In Hostinger hPanel → Website → Details → Primary Domain → shows the path.
Finding your SSH port: Some Hostinger accounts use port 22, others a custom port (e.g., 65002). Check your SSH details in hPanel.
3. Test the connection
ssh -p 65002 u528135200@your-hostname.com "echo 'SSH OK'"
4. Run first deploy
bash deploy.sh
# Output:
# === Building ===
# === Rsyncing to Hostinger ===
# === Adding SPA routing rule ===
# === Live at https://your-domain.com ===
Deployment Commands
# Standard deploy (build + push)
bash deploy.sh
# Push only (skip build — if dist/ is already built locally)
bash deploy.sh --no-build
# Dry run (see what would be pushed, no changes made)
rsync -avzn -e "ssh -p 65002" dist/ u528135200@host:/home/username/domains/example.com/public_html/
# Rollback: restore a previous deploy
# Hostinger keeps previous versions in hPanel → Backups → Website Backups
# Or use rsync in reverse:
rsync -avz -e "ssh -p 65002" \
--delete \
u528135200@host:/home/username/domains/example.com/public_html/ \
dist-rollback/
SPA Routing (.htaccess)
The script automatically injects this .htaccess if missing or updates it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
This routes all 404s to index.html, enabling client-side routing for React Router, Vue Router, etc.
GitHub Actions CI/CD (Optional)
Add automatic deploys on every push to main:
# .github/workflows/deploy.yml
name: Deploy to Hostinger
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install & Build
run: |
npm ci
npm run build
- name: Deploy to Hostinger
env:
HOST: ${{ secrets.HOSTINGER_HOST }}
PORT: ${{ secrets.HOSTINGER_PORT }}
DEST: ${{ secrets.HOSTINGER_DEST }}
run: |
chmod +x deploy.sh
./deploy.sh
# Note: deploy.sh should use SSH key authentication
# Add private key via secrets.HOSTINGER_SSH_KEY
Add secrets to your GitHub repo: Settings → Secrets → Actions:
HOSTINGER_HOST—u528135200@your-domain.comHOSTINGER_PORT—22or65002HOSTINGER_DEST—/home/username/domains/your-domain.com/public_htmlHOSTINGER_SSH_KEY— your private SSH key (base64 encoded or use actions/checkout with deploy key)
One-Command Push (without build)
If dist/ is already up-to-date locally and you just want to push:
rsync -avz --delete \
-e "ssh -p 65002" \
--exclude '.htaccess' \
dist/ \
u528135200@host:/home/username/domains/example.com/public_html/
Files
scripts/deploy.sh— the deploy script (edit the config section at the top)docs/config.md— step-by-step setup guide with Hostinger-specific instructions
