šŸš€ Complete Setup Guide (For Beginners)

Step-by-step instructions to set up your SaaS boilerplate on AWS Lightsail + Plesk + PostgreSQL. Written for beginners with zero assumptions.

By Super Admin39 views

Complete SaaS Boilerplate Setup Guide

For Beginners: This guide assumes you're new to deployment. We'll walk through every step, including the "obvious" ones.

Stack: AWS Lightsail + PostgreSQL + Plesk + PM2 (same setup used for AI Startup SEO & Demo subdomain)

Time: ~2-3 hours first time, ~30 minutes after you've done it once


šŸ“‹ What You'll Need

Before starting, have these ready:

āœ… Domain name (e.g., yourstartup.ai) āœ… Credit card for AWS (~$10-20/month) āœ… Boilerplate license key (emailed after purchase) āœ… Computer with internet connection āœ… 1-2 hours of focused time

Optional but recommended:


šŸŽÆ Overview: What We're Building

By the end of this guide, you'll have:

yourstartup.ai (production)
  ↳ Running on AWS Lightsail
  ↳ Managed with Plesk
  ↳ Connected to PostgreSQL database
  ↳ SSL certificate (https)
  ↳ PM2 process manager

Optional: staging.yourstartup.ai (test environment)

Step 1: Set Up AWS Lightsail Server

1.1 Create AWS Account

  1. Go to aws.amazon.com
  2. Click "Create an AWS Account"
  3. Enter email, password, account name
  4. Add credit card (required, but we'll use free tier where possible)
  5. Verify phone number
  6. Choose "Basic Support - Free" plan

1.2 Create Lightsail Instance

  1. Log into AWS Console
  2. Search for "Lightsail" in the top search bar
  3. Click "Create instance" (orange button)

Configure instance:

  • Region: Choose closest to your users (e.g., us-east-1 for USA)
  • Platform: Linux/Unix
  • Blueprint: Click "Apps + OS" → Select "Plesk"
  • Instance plan:
    • Recommended: $10/month (1 GB RAM, 40 GB SSD) for testing
    • Production: $20/month (2 GB RAM, 60 GB SSD) for real traffic
  • Name your instance: yourstartup-production
  • Click "Create instance"

Wait 3-5 minutes for server to start (status changes from "Pending" to "Running").

1.3 Get Server IP Address

  1. Click on your instance name
  2. Copy the Public IP (looks like 34.123.45.67)
  3. Save this IP - you'll need it multiple times

1.4 Set Up Static IP (Important!)

By default, Lightsail IPs change when you restart. Let's fix that:

  1. On instance page, click "Networking" tab
  2. Scroll to "Static IP" section
  3. Click "Create static IP"
  4. Name it: yourstartup-static-ip
  5. Click "Create"

Now your IP won't change even if server restarts.


Step 2: Point Your Domain to Server

2.1 Update DNS Records

Go to where you bought your domain (Namecheap, GoDaddy, Cloudflare, etc.) and add these DNS records:

Main domain:

Type: A
Name: @
Value: YOUR_STATIC_IP (e.g., 34.123.45.67)
TTL: Automatic or 3600

Optional staging subdomain:

Type: A
Name: staging
Value: YOUR_STATIC_IP (same IP)
TTL: Automatic or 3600

Wait 5-30 minutes for DNS to propagate. You can check progress:


Step 3: Access Plesk Admin Panel

3.1 Get Plesk Login Credentials

  1. Go back to AWS Lightsail Console

  2. Click on your instance

  3. Click "Connect using SSH" (browser-based terminal opens)

  4. Run this command to get Plesk password:

sudo plesk login

This outputs a URL like:

https://34.123.45.67:8443/login?secret=abc123def456...
  1. Copy the entire URL
  2. Paste it in your browser (ignore "Not Secure" warning - click "Advanced" → "Proceed")

3.2 Set Up Plesk Admin

  1. Username: admin (or root)
  2. Set a strong password (save it in password manager!)
  3. Enter your email for notifications
  4. Accept license terms
  5. Click "Enter Plesk"

You're now in Plesk! This is your server control panel.


Step 4: Create PostgreSQL Database

4.1 Set Up AWS RDS PostgreSQL

Why separate database? Easier backups, better performance, can scale independently.

  1. Go to AWS Console → Search for "RDS"
  2. Click "Create database"

Configure:

  • Engine: PostgreSQL
  • Templates: Free tier (for testing) or Production (for real traffic)
  • DB instance identifier: yourstartup-db
  • Master username: dbadmin (or your choice)
  • Master password: Generate a strong password (save it!)
  • DB instance class:
    • Free tier: db.t3.micro
    • Production: db.t3.small or higher
  • Storage: 20 GB (free tier)
  • Public access: YES (important - we need Plesk to connect)
  • VPC security group: Create new
    • Group name: yourstartup-db-sg
  • Database name: yourstartup_production
  1. Click "Create database"
  2. Wait 5-10 minutes for database to be ready (status: "Available")

4.2 Get Database Connection String

  1. Click on your database instance
  2. Copy the "Endpoint" (looks like yourstartup-db.abc123.us-east-1.rds.amazonaws.com)
  3. Note the Port (usually 5432)

Your connection string format:

postgresql://USERNAME:PASSWORD@ENDPOINT:5432/DATABASE_NAME

Example:

postgresql://dbadmin:MyStr0ngP@[email protected]:5432/yourstartup_production

If password has special characters, URL-encode them:

  • ! → %21
  • @ → %40
  • # → %23
  • $ → %24
  • % → %25
  • & → %26
  • Space → %20

4.3 Allow Plesk Server to Connect

  1. In AWS RDS console, click your database
  2. Click the security group link (under "VPC security groups")
  3. Click "Inbound rules" tab
  4. Click "Edit inbound rules"
  5. Click "Add rule":
    • Type: PostgreSQL
    • Port: 5432
    • Source: Custom
    • Value: Your Plesk server IP (e.g., 34.123.45.67/32)
  6. Click "Save rules"

Test connection from Plesk SSH:

psql "postgresql://dbadmin:PASSWORD@your-db-endpoint:5432/yourstartup_production"

If it connects, you'll see:

yourstartup_production=#

Type \q to exit.


Step 5: Add Domain to Plesk

  1. In Plesk, click "Add Domain" (big blue button)
  2. Enter your domain: yourstartup.ai
  3. Hosting type: Website hosting
  4. Click "Add Domain"

Plesk automatically:

  • āœ… Creates folder: /var/www/vhosts/yourstartup.ai
  • āœ… Sets up Apache/Nginx
  • āœ… Requests SSL certificate (takes 2-5 minutes)

Repeat for staging (if you want):

  • Add domain: staging.yourstartup.ai

Step 6: Install Node.js in Plesk

  1. In Plesk sidebar, go to "Tools & Settings"
  2. Click "Updates" (under "Server Management")
  3. Click "Add/Remove Components"
  4. Find "Node.js" → Check the box
  5. Click "Continue"
  6. Wait for installation (~5 minutes)

Set default Node.js version:

  1. Go back to your domain (yourstartup.ai)
  2. Click "Node.js" in the sidebar
  3. Node.js version: Select 18.x or 20.x (latest LTS)
  4. Document root: /yourstartup.ai (or httpdocs)
  5. Application mode: Production
  6. Application startup file: We'll set this later
  7. Click "Enable Node.js"

Step 7: Deploy Boilerplate Code

7.1 SSH into Server

Option A: Browser SSH (easiest)

  • AWS Lightsail Console → Click instance → "Connect using SSH"

Option B: Terminal/PuTTY

ssh ubuntu@YOUR_SERVER_IP
# Or on Windows: Use PuTTY with IP and port 22

7.2 Navigate to Domain Folder

cd /var/www/vhosts/yourstartup.ai
ls  # You'll see: httpdocs, logs, tmp, etc.

7.3 Clone Boilerplate Repository

You received a GitHub repo URL with your purchase. Replace YOUR_REPO_URL:

git clone YOUR_REPO_URL yourstartup.ai
cd yourstartup.ai

If private repo (need authentication):

git clone https://[email protected]/username/repo.git yourstartup.ai

7.4 Install Dependencies

npm install

This takes 2-5 minutes. Don't worry about warnings (only errors matter).


Step 8: Configure Environment Variables

8.1 Create .env File

nano .env
# Or use: vim .env

Paste this template (replace ALL_CAPS with your values):

# ===================================
# SERVER
# ===================================
NODE_ENV=production
PORT=3000
NEXT_PUBLIC_APP_URL=https://yourstartup.ai

# ===================================
# DATABASE
# ===================================
DATABASE_URL="postgresql://USER:PASSWORD@ENDPOINT:5432/DB_NAME?schema=public&connection_limit=20"

# ===================================
# AUTHENTICATION
# ===================================
NEXTAUTH_URL=https://yourstartup.ai
NEXTAUTH_SECRET=GENERATE_THIS_WITH_COMMAND_BELOW

# ===================================
# ENCRYPTION
# ===================================
ENCRYPTION_KEY=GENERATE_THIS_WITH_COMMAND_BELOW
HMAC_SECRET=GENERATE_THIS_WITH_COMMAND_BELOW

# ===================================
# LICENSE
# ===================================
BOILERPLATE_LICENSE_KEY="BP-XXXX-XXXX-XXXX"

# ===================================
# STRIPE (Get from dashboard.stripe.com)
# ===================================
STRIPE_SECRET_KEY=sk_live_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...

# ===================================
# EMAIL (SendGrid - get from sendgrid.com)
# ===================================
SENDGRID_API_KEY=SG....
[email protected]

# ===================================
# SUPER ADMIN
# ===================================
[email protected]

Generate secret keys:

# Generate NEXTAUTH_SECRET
openssl rand -base64 32

# Generate ENCRYPTION_KEY
openssl rand -base64 32

# Generate HMAC_SECRET
openssl rand -base64 32

Copy each output and paste into .env.

Save file:

  • Nano: Ctrl+O, Enter, Ctrl+X
  • Vim: :wq, Enter

Step 9: Set Up Database Schema

9.1 Generate Prisma Client

npx prisma generate

9.2 Push Database Schema

npx prisma db push

This creates all tables in your PostgreSQL database. You'll see output like:

āœ” Generated Prisma Client
āœ” Applied database changes

9.3 Create First Admin User

npx prisma studio

This opens a database GUI in your browser:

  1. Click "User" table
  2. Click "Add record"
  3. Fill in:
    • email: [email protected]
    • name: Your name
    • password: (leave blank for now - we'll set via "Forgot Password")
    • role: SUPER_ADMIN
  4. Click "Save 1 change"

Close Prisma Studio (Ctrl+C in terminal).


Step 10: Build & Start Application

10.1 Build Production Bundle

npm run build

This takes 2-5 minutes. You'll see:

āœ“ Compiled successfully
āœ“ Collecting page data
āœ“ Generating static pages

10.2 Start with PM2

PM2 keeps your app running even after you close SSH.

Install PM2 globally:

npm install -g pm2

Start app:

pm2 start npm --name "yourstartup-prod" -- start

Save PM2 config (so it auto-starts on reboot):

pm2 save
pm2 startup
# Copy-paste the command it outputs and run it

Check status:

pm2 list

You should see:

│ yourstartup-prod │ online │

View logs:

pm2 logs yourstartup-prod

Look for:

ā–² Next.js 16.1.6
āœ“ Ready on http://localhost:3000

Step 11: Configure Plesk Proxy

Your app runs on localhost:3000, but users visit https://yourstartup.ai. Plesk needs to proxy requests.

11.1 Add Apache Directives

  1. In Plesk, go to your domain (yourstartup.ai)
  2. Click "Apache & nginx Settings"
  3. Scroll to "Additional directives for HTTP"

Paste:

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
LimitRequestLine 16384
LimitRequestFieldSize 16384
  1. Scroll to "Additional directives for HTTPS"

Paste the same:

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
LimitRequestLine 16384
LimitRequestFieldSize 16384
  1. Scroll to "Additional nginx directives"

Paste:

large_client_header_buffers 4 32k;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host $host;
  1. Click "OK"

11.2 Test Your Site

Visit: https://yourstartup.ai

You should see your boilerplate homepage! šŸŽ‰

If you see errors:

  • Check PM2 logs: pm2 logs yourstartup-prod
  • Check database connection: psql "YOUR_DATABASE_URL"
  • Check port 3000 isn't blocked: curl http://localhost:3000

Step 12: Set Your Admin Password

  1. Visit: https://yourstartup.ai/forgot-password
  2. Enter your admin email ([email protected])
  3. Click "Send Reset Link"
  4. Check your email
  5. Click the reset link
  6. Set a strong password
  7. Log in at /admin

You're in! šŸš€


Step 13: Configure Stripe Webhooks

  1. Go to dashboard.stripe.com/webhooks
  2. Click "Add endpoint"
  3. Endpoint URL: https://yourstartup.ai/api/webhooks/stripe
  4. Events to send:
    • checkout.session.completed
    • invoice.payment_succeeded
    • customer.subscription.deleted
    • customer.subscription.updated
  5. Click "Add endpoint"
  6. Copy the "Signing secret" (starts with whsec_)
  7. Update your .env:
nano /var/www/vhosts/yourstartup.ai/yourstartup.ai/.env
# Add: STRIPE_WEBHOOK_SECRET=whsec_...
  1. Restart app:
pm2 restart yourstartup-prod

šŸŽ‰ You're Done!

Your SaaS is live at:

  • 🌐 Homepage: https://yourstartup.ai
  • šŸ” Admin: https://yourstartup.ai/admin
  • šŸ‘¤ User Login: https://yourstartup.ai/login
  • šŸ“š Docs: https://yourstartup.ai/docs

šŸ”§ Common Issues & Fixes

Issue: "Cannot connect to database"

Fix:

  1. Check RDS security group allows your server IP
  2. Test connection: psql "YOUR_DATABASE_URL"
  3. Verify password is URL-encoded in .env

Issue: "Port 3000 already in use"

Fix:

pm2 list  # Check what's running
pm2 stop yourstartup-prod
pm2 start yourstartup-prod

Issue: SSL certificate not working

Fix:

  1. Wait 10-15 minutes for Plesk to request cert
  2. Check DNS propagation: dnschecker.org
  3. In Plesk → SSL/TLS Certificates → Click "Reissue"

Issue: Stripe webhooks failing

Fix:

  1. Check webhook secret matches in .env
  2. Visit Stripe Dashboard → Webhooks → View recent attempts
  3. Check PM2 logs: pm2 logs yourstartup-prod

šŸ“– Next Steps

  1. Customize branding - See Customization Guide
  2. Set up staging - Repeat these steps for staging.yourstartup.ai (use port 3001)
  3. Configure email - SendGrid Setup Guide
  4. Learn Git workflow - Staging → Production Guide

šŸ†˜ Need Help?

  • šŸ“§ Email: [email protected] (include your license key)
  • šŸ“– Full docs: docs.aistartupseo.com
  • šŸŽ« Include in support request:
    • License key
    • Domain name
    • PM2 logs (pm2 logs)
    • Error screenshots

Congratulations on launching your SaaS! šŸš€

Was this article helpful?

Let us know so we can improve our docs