ZTechUniverse

Deploy Apps with AWS Lightsail and CapRover

2025-01-20 · 5 min read

Deploy your app for $5–10/month with AWS Lightsail and CapRover. No Kubernetes, no complex setup. This guide walks you through each step with images for each section.


What You'll Need

  • An AWS account
  • A domain name (e.g. yourdomain.com)
  • Your app code in a Git repo or a Dockerfile

Cost: $5–10/month for Lightsail. CapRover is free and open source.


Step 1: Create a Lightsail Instance

Go to AWS Lightsail and create a new instance.

AWS Lightsail create instance — Choose region, platform Linux/Unix, blueprint OS Only Ubuntu 22.04, select $5 or $10 plan

What to choose:

  1. Region — Pick one close to your users (e.g. us-east-1).
  2. Platform — Linux/Unix.
  3. Blueprint — OS Only → Ubuntu 22.04.
  4. Plan — $5 or $10 for small apps.
  5. Name — e.g. caprover-server.

Click Create instance. Wait 1–2 minutes for it to start.

Important: After creation, go to NetworkingCreate static IP and attach it to your instance. This keeps your IP address fixed when you reboot.


Step 2: Install Docker and CapRover

Click the SSH button on your instance to open a terminal in the browser. Or use your own SSH client.

Terminal — Run Docker install and caprover setup commands

Run these commands one by one:

Bash
# 1. Install Docker curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker $USER

Log out and log back in (or run newgrp docker). Then:

Bash
# 2. Install CapRover npm install -g caprover caprover setup

During caprover setup you will:

  • Enter your root domain (e.g. captain.yourdomain.com).
  • Set a password for the CapRover dashboard.
  • See instructions to add a DNS A record pointing to your Lightsail static IP.

Do the DNS step now. Add an A record: captain.yourdomain.com → your static IP. Wait a few minutes for DNS to propagate, then continue.


Step 3: Open Ports in Lightsail

CapRover needs ports 80 and 443 for HTTP/HTTPS.

Lightsail Networking tab — Add firewall rules for HTTP 80 and HTTPS 443

  1. Go to your instance → Networking tab.
  2. Click Add rule.
  3. Add: HTTP (80) and HTTPS (443).
  4. Save.

Step 4: Deploy Your App

Open https://captain.yourdomain.com in your browser. Log in with the password you set.

CapRover Apps — Create new app and connect your repo or Dockerfile

To deploy:

  1. Go to AppsCreate new app (e.g. myapp).
  2. Set App URL (e.g. app.yourdomain.com).
  3. Enable HTTPS — CapRover will get a free SSL certificate.
  4. Add a DNS A record for app.yourdomain.com → your static IP.
  5. Connect your GitHub/GitLab repo or upload a Dockerfile.
  6. Click Deploy.

CapRover will build and run your app. Your app will be live at https://app.yourdomain.com.

Simple Dockerfile for a Node app:

Dockerfile
FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . EXPOSE 3000 CMD ["node", "index.js"]

Step 5: HTTP Settings — Domains and Container Port

After creating your app, click on it and go to the HTTP Settings tab. This is where you configure domains, HTTPS, and the port your app listens on.

CapRover HTTP Settings — Add custom domains, enable HTTPS, set Container HTTP Port

Key settings:

  • Custom domains — Add app.yourdomain.com and www.yourdomain.com. Each gets its own SSL.
  • Enable HTTPS — Click to get a free Let's Encrypt certificate.
  • Force HTTPS — Redirect HTTP to HTTPS (recommended).
  • Container HTTP Port — Set to the port your app listens on (e.g. 3000 for Node/Express). If you get a 502 error, this is usually the fix.

Step 6: App Config — Environment Variables

In your app's CapRover settings, go to App ConfigsEnvironment Variables.

CapRover App Config — Environment Variables section for DATABASE_URL, API keys, etc.

Add variables like:

  • NODE_ENV=production
  • DATABASE_URL=your-connection-string
  • Any API keys your app needs

Click Save and Restart the app. Variables are available as process.env.VAR_NAME in Node.js.


Troubleshooting

ProblemFix
Dashboard won't loadCheck DNS for captain.yourdomain.com points to static IP. Ensure ports 80/443 are open.
App build failsCheck build logs in CapRover. Verify Dockerfile path and package.json build script.
HTTPS errorsEnsure app domain A record points to static IP. Wait for DNS propagation.
App returns 502Set Container HTTP Port in HTTP Settings to match your app (e.g. 3000).

You're done. You now have a simple, cost-effective way to deploy apps. For backend patterns, see Backend Best Practices.