Skip to content

Install Backend

This guide will walk you through setting up the Stelo CMS backend on your development machine and deploying it to production.

Before starting, ensure you have:

  • Node.js 18+ (recommended: use nvm)
  • npm or pnpm (recommended)
  • Git for version control
  • Docker (for local PostgreSQL)
  • Digital Ocean account (for production)
Terminal window
# Clone the Stelo CMS template
git clone https://github.com/your-username/template-stelo-cms.git client-project-cms
cd client-project-cms
# Remove the original git history
rm -rf .git
git init
git add .
git commit -m "Initial commit from Stelo CMS template"
Terminal window
# Using pnpm (recommended)
pnpm install
# Or using npm
npm install

Copy the environment template and configure your variables:

Terminal window
cp .env.example .env.local

Edit .env.local with your configuration:

Terminal window
# Database
DATABASE_URL="postgresql://postgres:password@localhost:5432/stelo_cms"
# NextAuth.js
NEXTAUTH_SECRET="your-super-secret-key-here"
NEXTAUTH_URL="http://localhost:3000"
# Digital Ocean Spaces (for file uploads)
DO_SPACES_ENDPOINT="https://fra1.digitaloceanspaces.com"
DO_SPACES_BUCKET="your-bucket-name"
DO_SPACES_ACCESS_KEY="your-access-key"
DO_SPACES_SECRET_KEY="your-secret-key"
# Optional: Google OAuth
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# Optional: Email provider (for notifications)
SMTP_HOST="smtp.gmail.com"
SMTP_PORT="587"
SMTP_USER="your-email@gmail.com"
SMTP_PASSWORD="your-app-password"
Terminal window
# Start PostgreSQL container
docker run --name stelo-postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=stelo_cms \
-p 5432:5432 \
-d postgres:17-alpine
# Verify connection
docker exec -it stelo-postgres psql -U postgres -d stelo_cms -c "SELECT version();"
  1. Create a PostgreSQL database in Digital Ocean
  2. Update DATABASE_URL in .env.local with the connection string
  3. Ensure your IP is added to trusted sources
Terminal window
# Generate Prisma client
pnpm prisma generate
# Run database migrations
pnpm prisma db push
# Seed the database with initial data
pnpm prisma db seed
Terminal window
# Start the development server
pnpm dev
# The CMS will be available at:
# http://localhost:3000

Visit http://localhost:3000/admin/setup to create your first admin user, or use the seed script:

Terminal window
# Run the admin setup script
pnpm run setup:admin
Terminal window
# Create a new droplet (2GB Memory / 50GB Disk / Ubuntu 24.04)
# Note the IP address for later configuration
Terminal window
# Create a PostgreSQL database cluster
# Note the connection details for environment variables
Terminal window
# Create a Digital Ocean Space
# Generate access keys for file uploads
Terminal window
# SSH into your VPS
ssh root@your-vps-ip
# Install Coolify
curl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash
# Access Coolify at http://your-vps-ip:8000
  1. Source: Connect your Git repository
  2. Build Pack: Node.js
  3. Environment Variables: Add production variables
Terminal window
# Database (Digital Ocean Managed)
DATABASE_URL="postgresql://username:password@host:port/database?sslmode=require"
# NextAuth.js
NEXTAUTH_SECRET="production-secret-key"
NEXTAUTH_URL="https://cms.your-domain.com"
# Digital Ocean Spaces
DO_SPACES_ENDPOINT="https://fra1.digitaloceanspaces.com"
DO_SPACES_BUCKET="client-assets"
DO_SPACES_ACCESS_KEY="production-access-key"
DO_SPACES_SECRET_KEY="production-secret-key"
# Email
SMTP_HOST="smtp.gmail.com"
SMTP_PORT="587"
SMTP_USER="noreply@your-domain.com"
SMTP_PASSWORD="production-password"

Create Dockerfile in your project root:

FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json pnpm-lock.yaml* ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build the application
RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
  1. Push to Git: Commit and push your changes
  2. Deploy in Coolify: Click “Deploy” in your Coolify dashboard
  3. Run Migrations: Execute database migrations in production
Terminal window
# SSH into your production container
docker exec -it your-container-name bash
# Run production migrations
npx prisma migrate deploy
# Create admin user
npm run setup:admin

Coolify automatically handles SSL certificates via Let’s Encrypt.

Point your domain to your VPS IP:

Type: A
Name: cms.your-domain.com
Value: your-vps-ip
TTL: 300
Terminal window
# On your VPS
ufw allow ssh
ufw allow 80
ufw allow 443
ufw allow 8000 # Coolify
ufw --force enable
  • Use strong, unique passwords
  • Enable 2FA where possible
  • Regularly rotate API keys
  • Monitor access logs
  • Use connection pooling
  • Enable SSL connections
  • Regular backups
  • Monitor query performance
Terminal window
# Check database connectivity
npx prisma studio
# Reset database schema
npx prisma migrate reset
Terminal window
# Clear build cache
rm -rf .next
rm -rf node_modules
pnpm install
pnpm build
Terminal window
# Verify environment variables
printenv | grep DATABASE_URL
printenv | grep NEXTAUTH_SECRET
Terminal window
# View Coolify logs
docker logs your-container-name
# View real-time logs
docker logs -f your-container-name
Terminal window
# Check database performance
npx prisma studio

After successful installation:

  1. Configure Entities - Set up your content structure
  2. Setup Permissions - Configure user roles
  3. Install Frontend - Deploy your client site
  • Weekly: Check application logs and performance
  • Monthly: Update dependencies and security patches
  • Quarterly: Database maintenance and optimization
  • Annually: Rotate API keys and certificates