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
- Log in to Digital Ocean
- Click Create → Droplets
- 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
- Click Create Droplet
- 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_IPStep 3: Initial Server Setup
Update system packages
apt update && apt upgrade -yInstall 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 versionInstall Git
apt install git -yCreate application directory
mkdir -p /var/www/nbharat24
cd /var/www/nbharat24docker 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 .envUpdate 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 32Save 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 -fOption B: With Nginx (Recommended for Production)
# 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 -fStep 7: Verify Deployment
Check running containers
docker compose psYou 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/healthCheck 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 -yCreate Nginx configuration
nano /etc/nginx/sites-available/nbharat24Paste 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 nginxStep 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 statusStep 10: Setup SSL with Let's Encrypt (Recommended)
# 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-runUpdate 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 appStep 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:seedStep 12: Access Your Application
- Admin Dashboard:
http://YOUR_DOMAIN/dashboard - Default Admin Login:
- Email: As set in
DEFAULT_ADMIN_EMAIL - Username: As set in
DEFAULT_ADMIN_USERNAME - Password: As set in
DEFAULT_ADMIN_PASSWORD
- Email: As set in
⚠️ 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 nginxRestart services
# Restart all
docker compose restart
# Restart specific service
docker compose restart appUpdate application
cd /var/www/nbharat24
git pull
docker compose up -d --buildBackup 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.sqlBackup 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 -hClean up unused Docker resources
docker system prune -a --volumesTroubleshooting
Application won't start
# Check logs
docker compose logs app
# Check if database is ready
docker compose ps postgres
# Restart services
docker compose restartDatabase 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 pushMedia uploads not working
# Check storage volume
docker volume inspect nbharat24_media_storage
# Check permissions
docker compose exec app ls -la /app/public/storagePort already in use
# Find process using port 8000
lsof -i :8000
# Kill process or change port in docker-compose.ymlSecurity 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-upgradesMonitor resource usage
# CPU and memory
htop
# Docker stats
docker statsSupport
For issues or questions:
- Check application logs:
docker compose logs -f - Check system logs:
journalctl -xe - Verify environment variables:
docker compose exec app env | grep -E 'DATABASE|JWT|NEXTAUTH'
Last Updated: 2024 Version: 1.0.0