Deploying a static site shouldn’t take ten steps. Here’s the script that reduced mine to one.

The problem

Every deploy looked like this:

  1. Build the project locally
  2. rsync the output folder to the VPS
  3. SSH in and reload Nginx
  4. Check the logs

Repetitive, error-prone, easy to forget a step.

The solution

A 30-line Bash script that does all four steps in sequence and exits loudly if any step fails.

#!/usr/bin/env bash
set -euo pipefail

BUILD_DIR="./dist"
REMOTE_USER="deploy"
REMOTE_HOST="vps.example.com"
REMOTE_PATH="/var/www/site"

echo "[1/3] Building..."
npm run build

echo "[2/3] Syncing files..."
rsync -az --delete "$BUILD_DIR/" "$REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH"

echo "[3/3] Reloading Nginx..."
ssh "$REMOTE_USER@$REMOTE_HOST" "sudo systemctl reload nginx"

echo "Done."

The key is set -euo pipefail — any failed command aborts the whole script instead of silently continuing.

Making it portable

Store the remote config in a .env file at the repo root and source it at the top of the script. Add .env to .gitignore. Done.

Currently used in production for the Laravel Finance App.