Self-Hosting 101

Move from managed hosting to self-hosting on your own AWS EC2 instance.

Self-Hosting 101

Own the infrastructure when you graduate from Vercel's free tier. Follow this checklist to spin up an EC2 box, deploy manually with pnpm, and keep it running.


Quick Checklist

  1. Confirm GitHub, Git, Node.js, Supabase access from Dev Environment Setup
  2. Install pnpm and prove the app builds locally
  3. Create an AWS account and launch a Ubuntu EC2 instance
  4. SSH in, install Node.js + pnpm, clone your repo
  5. pnpm install, pnpm build, pnpm start on the server
  6. Add PM2 (optional) and wire up a custom domain if needed

1. Local Pre-Flight

Install pnpm once:

npm install -g pnpm
pnpm --version

From your project root:

pnpm install
pnpm build
pnpm start   # visit http://localhost:3000

Commit and push the working state to GitHub so the server can pull it.


2. AWS Account and Instance

  1. Sign in at aws.amazon.com and choose the Free Tier
  2. Search for EC2 → Launch instance with:
    • Name: nextjs-server
    • OS: Ubuntu 24.04 LTS
    • Instance type: t2.micro (Free Tier)
    • Create a new key pair (.pem download)
    • Allow HTTP (80) and HTTPS (443) in security group
  3. Wait for the instance to boot, then copy the Public IPv4 DNS

SSH into Your Server

chmod 400 your-key.pem
ssh -i your-key.pem ubuntu@ec2-xx-xx-xx-xx.compute-1.amazonaws.com

3. Prepare the Server

Run these commands on the EC2 shell:

sudo apt update
sudo apt install -y git curl
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
sudo npm install -g pnpm
node --version && pnpm --version

Store environment variables (Supabase keys, etc.) in a .env file or the shell profile. Keep secrets out of git.


4. Deploy from GitHub

git clone https://github.com/yourusername/your-repo.git
cd your-repo
cp .env.production .env   # if you keep a template
pnpm install
pnpm build
pnpm start

Visit http://<your-public-dns> in the browser. Your Next.js app should load. Use Ctrl + C to stop the process.


5. Keep It Running with PM2

sudo npm install -g pm2
pm2 start "pnpm start" --name "nextjs-app"
pm2 save
pm2 startup   # follow the printed instructions

Useful PM2 Commands

CommandPurpose
pm2 statusEnsure the process is online
pm2 logs nextjs-appView runtime logs
pm2 resurrectRestore after reboot

6. Custom Domain (Optional)

  1. Buy a domain (Namecheap, etc.)
  2. In AWS Route 53 → Hosted Zone → create an A record pointing to the EC2 public IP
  3. Update nameservers with your registrar to the ones Route 53 provides
  4. Consider adding Nginx + SSL (Let's Encrypt) once traffic increases

Validation Checklist

StageCommandWhat to Check
Local devpnpm devUI works while coding
Local productionpnpm build && pnpm startBundled app renders
Remote buildpnpm install && pnpm buildDependencies available
Remote runtimepm2 statusApp stays online after deploy

Log any failures in Troubleshooting with the command you ran and the error snippet.


Practice Challenge

  1. Create a test Next.js app with pnpm create next-app
  2. Push it to GitHub and deploy to EC2 using the flow above
  3. Add a /status route that prints environment info
  4. Confirm you can reach /status from the public URL

You now control the full stack—from prompts to production hardware.


Need CLI command references? See CLI Services.

Back to the main workflow? Return to Build with AI Flow.