Skip to main content

Digital Ocean Production Deployment Guide

Step-by-step guide to integrating

––– views

Digital Ocean Production Deployment Guide

Complete, step‑by‑step guide to deploy NBharat24 to Digital Ocean using Docker, PostgreSQL, and Nginx.

Use this when you want a repeatable single‑server production setup with clear commands you can copy‑paste.

Prerequisites

  • Digital Ocean account
  • Domain name (optional but recommended)
  • SSH access to your server
  • Git repository access

Step 1: Create Digital Ocean Droplet

  1. Log in to Digital Ocean
  2. Click CreateDroplets
  3. Choose configuration:
    • Image: Ubuntu 22.04 LTS
    • Plan: Basic (minimum 2GB RAM, 1 vCPU recommended)
    • Datacenter: Choose closest to your users
    • Authentication: SSH keys (recommended) or password
  4. Click Create Droplet
  5. Note your droplet's IP address

Step 2: Connect to Server

# Connect via SSH (replace with your IP and user)
ssh root@YOUR_SERVER_IP
 
# Or if using a non-root user
ssh your_username@YOUR_SERVER_IP

Step 3: Initial Server Setup

Update system packages

apt update && apt upgrade -y

Install Docker and Docker Compose

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
 
# Install Docker Compose
apt install docker-compose-plugin -y
 
# Verify installation
docker --version
docker compose version

Install Git

apt install git -y

Create application directory

mkdir -p /var/www/nbharat24
cd /var/www/nbharat24

docker compose restart app

Step 4: Clone Repository

# Clone your repository
git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git .
 
# Or if using private repo with SSH
git clone git@github.com:YOUR_USERNAME/YOUR_REPO.git .

Step 5: Setup Environment Variables

# Copy example environment file
cp .envs.example .env
 
# Edit environment file
nano .env

Update the following variables in .env:

# Database (will be used by docker-compose)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=CHANGE_THIS_STRONG_PASSWORD
POSTGRES_DB=n24_db_prod

# Application Database URL (matches docker-compose service name)
DATABASE_URL="postgresql://postgres:CHANGE_THIS_STRONG_PASSWORD@postgres:5432/n24_db_prod?schema=public"

# JWT Secret (generate a new one)
JWT_SECRET="YOUR_GENERATED_JWT_SECRET_MIN_32_CHARS"
JWT_EXPIRES_IN="7d"

# Application URLs (replace with your domain or IP)
NODE_ENV="production"
NEXTAUTH_URL="http://YOUR_DOMAIN_OR_IP"
APP_URL="http://YOUR_DOMAIN_OR_IP"
NEXT_PUBLIC_BASE_URL="http://YOUR_DOMAIN_OR_IP"
NEXTAUTH_SECRET="YOUR_GENERATED_NEXTAUTH_SECRET"

# OAuth (optional - configure if needed)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
WHATSAPP_CLIENT_ID="your-whatsapp-client-id"
WHATSAPP_CLIENT_SECRET="your-whatsapp-client-secret"

# Default Admin (change after first login)
DEFAULT_ADMIN_EMAIL="admin@yourdomain.com"
DEFAULT_ADMIN_USERNAME="admin"
DEFAULT_ADMIN_PASSWORD="CHANGE_THIS_STRONG_PASSWORD"

Generate secure secrets:

# Generate JWT_SECRET
openssl rand -base64 32
 
# Generate NEXTAUTH_SECRET
openssl rand -base64 32

Save and exit (Ctrl+X, then Y, then Enter)

Step 6: Build and Start Services

Option A: Without Nginx (Direct Access on Port 8000)

# Build and start containers
docker compose up -d --build
 
# View logs
docker compose logs -f
# Create nginx SSL directory (for future SSL setup)
mkdir -p nginx/ssl
 
# Start with nginx
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
 
# View logs
docker compose logs -f

Step 7: Verify Deployment

Check running containers

docker compose ps

You should see:

  • nbharat24_postgres (database)
  • nbharat24_app (Next.js application)
  • nbharat24_nginx (if using nginx)

Check application health

# From server
curl http://localhost:8000/api/health
 
# Or from your browser
http://YOUR_SERVER_IP:8000/api/health

Check database connection

# Connect to database container
docker compose exec postgres psql -U postgres -d n24_db_prod -c "SELECT version();"

Step 8: Setup Nginx (If not using docker-compose.prod.yml)

Install Nginx

apt install nginx -y

Create Nginx configuration

nano /etc/nginx/sites-available/nbharat24

Paste the configuration from nginx.conf and update:

  • Replace server_name _; with your domain name
  • Update upstream server if needed

Enable site

ln -s /etc/nginx/sites-available/nbharat24 /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t  # Test configuration
systemctl restart nginx

Step 9: Setup Firewall

# Allow SSH, HTTP, HTTPS
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
 
# Enable firewall
ufw enable
 
# Check status
ufw status
# Install Certbot
apt install certbot python3-certbot-nginx -y
 
# Get SSL certificate (replace with your domain)
certbot --nginx -d yourdomain.com -d www.yourdomain.com
# live
certbot --nginx -d nbharat24.com -d www.nbharat24.com
 
# Auto-renewal is set up automatically
certbot renew --dry-run

Update your .env file with HTTPS URLs:

NEXTAUTH_URL="https://yourdomain.com"
APP_URL="https://yourdomain.com"
NEXT_PUBLIC_BASE_URL="https://yourdomain.com"

Restart application:

docker compose restart app

Step 11: Initial Database Setup

The application will automatically run migrations on startup. To manually seed the database:

# Run database seed (creates default admin user)
docker compose exec app npm run db:seed

Step 12: Access Your Application

  1. Admin Dashboard: http://YOUR_DOMAIN/dashboard
  2. Default Admin Login:
    • Email: As set in DEFAULT_ADMIN_EMAIL
    • Username: As set in DEFAULT_ADMIN_USERNAME
    • Password: As set in DEFAULT_ADMIN_PASSWORD

⚠️ IMPORTANT: Change the default admin password immediately after first login!

Maintenance Commands

View logs

# All services
docker compose logs -f
 
# Specific service
docker compose logs -f app
docker compose logs -f postgres
docker compose logs -f nginx

Restart services

# Restart all
docker compose restart
 
# Restart specific service
docker compose restart app

Update application

cd /var/www/nbharat24
git pull
docker compose up -d --build

Backup database

# Create backup
docker compose exec postgres pg_dump -U postgres n24_db_prod > backup_$(date +%Y%m%d_%H%M%S).sql
 
# Restore from backup
docker compose exec -T postgres psql -U postgres n24_db_prod < backup_YYYYMMDD_HHMMSS.sql

Backup media files

# Backup media storage
docker run --rm -v nbharat24_media_storage:/data -v $(pwd):/backup alpine tar czf /backup/media_backup_$(date +%Y%m%d).tar.gz -C /data .

Check disk usage

docker system df
df -h

Clean up unused Docker resources

docker system prune -a --volumes

Troubleshooting

Application won't start

# Check logs
docker compose logs app
 
# Check if database is ready
docker compose ps postgres
 
# Restart services
docker compose restart

Database connection errors

# Verify database is running
docker compose ps postgres
 
# Check database logs
docker compose logs postgres
 
# Test connection
docker compose exec app npx prisma db push

Media uploads not working

# Check storage volume
docker volume inspect nbharat24_media_storage
 
# Check permissions
docker compose exec app ls -la /app/public/storage

Port already in use

# Find process using port 8000
lsof -i :8000
 
# Kill process or change port in docker-compose.yml

Security Checklist

  • Changed default admin credentials
  • Generated strong JWT_SECRET and NEXTAUTH_SECRET
  • Changed database password
  • Setup SSL/HTTPS
  • Configured firewall (UFW)
  • Disabled root SSH login (optional but recommended)
  • Setup automatic security updates
  • Regular backups configured

Monitoring

Setup automatic updates

apt install unattended-upgrades -y
dpkg-reconfigure -plow unattended-upgrades

Monitor resource usage

# CPU and memory
htop
 
# Docker stats
docker stats

Support

For issues or questions:

  1. Check application logs: docker compose logs -f
  2. Check system logs: journalctl -xe
  3. Verify environment variables: docker compose exec app env | grep -E 'DATABASE|JWT|NEXTAUTH'

Last Updated: 2024 Version: 1.0.0