Prerequisites
Before you begin, ensure you have:- A GitHub, GitLab, or Bitbucket account
- Your code pushed to a Git repository
- A Vercel account (free tier is sufficient to start)
- Production Stripe API keys
- A production PostgreSQL database (see database options)
Deployment Steps
Connect Repository to Vercel
- Go to vercel.com and sign in
- Click Add New → Project
- Import your Git repository
- Vercel will automatically detect Next.js and configure build settings
Vercel automatically detects the following:
- Framework: Next.js
- Build Command:
pnpm build - Output Directory:
.next - Install Command:
pnpm install
Configure Environment Variables
Before deploying, add all required environment variables in the Vercel dashboard:
- Click Environment Variables in the project settings
- Add each variable:
| Variable | Value | Notes |
|---|---|---|
BASE_URL | https://your-domain.vercel.app | Your production domain |
POSTGRES_URL | postgresql://... | Production database connection string |
STRIPE_SECRET_KEY | sk_live_... | Production Stripe secret key |
STRIPE_WEBHOOK_SECRET | whsec_... | Leave empty for now, add after webhook creation |
AUTH_SECRET | Generated string | Run openssl rand -base64 32 to generate |
Deploy
Click Deploy to start your first deployment.Vercel will:
- Clone your repository
- Install dependencies with
pnpm install - Build your application with
pnpm build - Deploy to their global edge network
Run Database Migrations
After your first deployment, you need to run database migrations.Option A: Using Vercel CLI (Recommended)Option B: Manually with psqlConnect to your database and run the SQL migrations from
lib/db/migrations/.Create Stripe Production Webhook
Now that your app is deployed, create a production webhook:
- Go to dashboard.stripe.com/webhooks
- Click Add endpoint
- Set endpoint URL:
https://your-domain.vercel.app/api/stripe/webhook - Select events to listen for:
customer.subscription.updatedcustomer.subscription.deleted
- Click Add endpoint
- Copy the Signing secret (starts with
whsec_...)
Add Webhook Secret to Vercel
- Go back to your Vercel project settings
- Navigate to Environment Variables
- Add or update
STRIPE_WEBHOOK_SECRETwith the signing secret from step 5 - Redeploy your application for the change to take effect
You can trigger a redeploy by going to Deployments → … menu on latest deployment → Redeploy.
Database Options
You need a production PostgreSQL database. Here are recommended options:Vercel Postgres (Recommended)
Pros: Native Vercel integration, automatic connection pooling, serverless-optimized- Go to your Vercel project
- Click Storage tab
- Click Create Database → Postgres
- Follow the setup wizard
- Vercel automatically adds
POSTGRES_URLto your environment variables
Neon
Pros: Serverless, automatic scaling, generous free tier- Sign up at neon.tech
- Create a new project
- Copy the connection string
- Add to Vercel as
POSTGRES_URL
Supabase
Pros: Includes auth and storage, good free tier- Sign up at supabase.com
- Create a new project
- Get connection string from project settings
- Add to Vercel as
POSTGRES_URL
More database options available at vercel.com/marketplace?category=databases.
Custom Domain Configuration
To use a custom domain instead of.vercel.app:
Configure DNS
Vercel will provide DNS configuration instructions:
- CNAME Record: Point to
cname.vercel-dns.com - A Record: Point to Vercel’s IP addresses
Update Environment Variables
Update Redeploy for changes to take effect.
BASE_URL in your environment variables:Update Stripe Webhook
Update your Stripe webhook endpoint URL to use the custom domain:
- Go to dashboard.stripe.com/webhooks
- Edit your webhook endpoint
- Update URL to
https://yourdomain.com/api/stripe/webhook
Automatic Deployments
Vercel automatically deploys your application when you push to your repository:- Production Branch (usually
main): Deploys to production domain - Other Branches: Creates preview deployments with unique URLs
- Pull Requests: Generates preview deployments for testing
Preview Deployments
Every pull request gets a unique preview URL:Monitoring and Logs
View Deployment Logs
- Go to your project dashboard
- Click Deployments
- Click on any deployment
- View build logs and runtime logs
Runtime Logs
View real-time application logs:Error Tracking
For production error tracking, consider integrating:Troubleshooting
Build Failures
Issue: Build fails with TypeScript errorsEnvironment Variable Issues
Issue: Application crashes due to missing environment variables- Verify all five required variables are set in Vercel
- Check for typos in variable names
- Redeploy after adding variables
Database Connection Errors
Issue: Cannot connect to database- Verify
POSTGRES_URLformat:postgresql://user:password@host:port/database - Ensure database allows connections from Vercel IPs
- Check if connection pooling is required
Webhook Signature Verification Failed
Issue: Stripe webhook returns 400 errors- Verify
STRIPE_WEBHOOK_SECRETmatches the webhook signing secret in Stripe Dashboard - Ensure you’re using the production webhook secret, not test
- Check that webhook URL exactly matches:
https://yourdomain.com/api/stripe/webhook
Next Steps
Production Checklist
Review production environment setup and security considerations