Install Backend
Backend Installation Guide
Section titled âBackend Installation GuideâThis guide will walk you through setting up the Stelo CMS backend on your development machine and deploying it to production.
Prerequisites
Section titled âPrerequisitesâ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)
Development Setup
Section titled âDevelopment Setupâ1. Clone the Template Repository
Section titled â1. Clone the Template Repositoryâ# Clone the Stelo CMS templategit clone https://github.com/your-username/template-stelo-cms.git client-project-cmscd client-project-cms
# Remove the original git historyrm -rf .gitgit initgit add .git commit -m "Initial commit from Stelo CMS template"2. Install Dependencies
Section titled â2. Install Dependenciesâ# Using pnpm (recommended)pnpm install
# Or using npmnpm install3. Environment Configuration
Section titled â3. Environment ConfigurationâCopy the environment template and configure your variables:
cp .env.example .env.localEdit .env.local with your configuration:
# DatabaseDATABASE_URL="postgresql://postgres:password@localhost:5432/stelo_cms"
# NextAuth.jsNEXTAUTH_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 OAuthGOOGLE_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"4. Database Setup
Section titled â4. Database SetupâOption A: Local PostgreSQL with Docker
Section titled âOption A: Local PostgreSQL with Dockerâ# Start PostgreSQL containerdocker run --name stelo-postgres \ -e POSTGRES_PASSWORD=password \ -e POSTGRES_DB=stelo_cms \ -p 5432:5432 \ -d postgres:17-alpine
# Verify connectiondocker exec -it stelo-postgres psql -U postgres -d stelo_cms -c "SELECT version();"Option B: Digital Ocean Managed Database
Section titled âOption B: Digital Ocean Managed Databaseâ- Create a PostgreSQL database in Digital Ocean
- Update
DATABASE_URLin.env.localwith the connection string - Ensure your IP is added to trusted sources
5. Database Migration
Section titled â5. Database Migrationâ# Generate Prisma clientpnpm prisma generate
# Run database migrationspnpm prisma db push
# Seed the database with initial datapnpm prisma db seed6. Start Development Server
Section titled â6. Start Development Serverâ# Start the development serverpnpm dev
# The CMS will be available at:# http://localhost:30007. Create Admin User
Section titled â7. Create Admin UserâVisit http://localhost:3000/admin/setup to create your first admin user, or use the seed script:
# Run the admin setup scriptpnpm run setup:adminProduction Deployment
Section titled âProduction Deploymentâ1. Prepare Digital Ocean Infrastructure
Section titled â1. Prepare Digital Ocean InfrastructureâVPS Setup
Section titled âVPS Setupâ# Create a new droplet (2GB Memory / 50GB Disk / Ubuntu 24.04)# Note the IP address for later configurationDatabase Setup
Section titled âDatabase Setupâ# Create a PostgreSQL database cluster# Note the connection details for environment variablesStorage Setup
Section titled âStorage Setupâ# Create a Digital Ocean Space# Generate access keys for file uploads2. Install Coolify on VPS
Section titled â2. Install Coolify on VPSâ# SSH into your VPSssh root@your-vps-ip
# Install Coolifycurl -fsSL https://cdn.coollabs.io/coolify/install.sh | bash
# Access Coolify at http://your-vps-ip:80003. Configure Deployment
Section titled â3. Configure DeploymentâCreate Application in Coolify
Section titled âCreate Application in Coolifyâ- Source: Connect your Git repository
- Build Pack: Node.js
- Environment Variables: Add production variables
Environment Variables (Production)
Section titled âEnvironment Variables (Production)â# Database (Digital Ocean Managed)DATABASE_URL="postgresql://username:password@host:port/database?sslmode=require"
# NextAuth.jsNEXTAUTH_SECRET="production-secret-key"NEXTAUTH_URL="https://cms.your-domain.com"
# Digital Ocean SpacesDO_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"
# EmailSMTP_HOST="smtp.gmail.com"SMTP_PORT="587"SMTP_USER="noreply@your-domain.com"SMTP_PASSWORD="production-password"4. Build Configuration
Section titled â4. Build ConfigurationâCreate Dockerfile in your project root:
FROM node:18-alpine AS base
# Install dependencies only when neededFROM base AS depsRUN apk add --no-cache libc6-compatWORKDIR /app
# Install dependencies based on the preferred package managerCOPY package.json pnpm-lock.yaml* ./RUN npm install -g pnpm && pnpm install --frozen-lockfile
# Rebuild the source code only when neededFROM base AS builderWORKDIR /appCOPY --from=deps /app/node_modules ./node_modulesCOPY . .
# Generate Prisma clientRUN npx prisma generate
# Build the applicationRUN npm run build
# Production image, copy all the files and run nextFROM base AS runnerWORKDIR /app
ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejsRUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image sizeCOPY --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"]5. Deploy Application
Section titled â5. Deploy Applicationâ- Push to Git: Commit and push your changes
- Deploy in Coolify: Click âDeployâ in your Coolify dashboard
- Run Migrations: Execute database migrations in production
# SSH into your production containerdocker exec -it your-container-name bash
# Run production migrationsnpx prisma migrate deploy
# Create admin usernpm run setup:admin6. Domain Configuration
Section titled â6. Domain ConfigurationâSSL Certificate
Section titled âSSL CertificateâCoolify automatically handles SSL certificates via Letâs Encrypt.
DNS Configuration
Section titled âDNS ConfigurationâPoint your domain to your VPS IP:
Type: AName: cms.your-domain.comValue: your-vps-ipTTL: 300Security Configuration
Section titled âSecurity Configurationâ1. Firewall Setup
Section titled â1. Firewall Setupâ# On your VPSufw allow sshufw allow 80ufw allow 443ufw allow 8000 # Coolifyufw --force enable2. Environment Security
Section titled â2. Environment Securityâ- Use strong, unique passwords
- Enable 2FA where possible
- Regularly rotate API keys
- Monitor access logs
3. Database Security
Section titled â3. Database Securityâ- Use connection pooling
- Enable SSL connections
- Regular backups
- Monitor query performance
Troubleshooting
Section titled âTroubleshootingâCommon Issues
Section titled âCommon IssuesâDatabase Connection Errors
Section titled âDatabase Connection Errorsâ# Check database connectivitynpx prisma studio
# Reset database schemanpx prisma migrate resetBuild Failures
Section titled âBuild Failuresâ# Clear build cacherm -rf .nextrm -rf node_modulespnpm installpnpm buildEnvironment Variable Issues
Section titled âEnvironment Variable Issuesâ# Verify environment variablesprintenv | grep DATABASE_URLprintenv | grep NEXTAUTH_SECRETMonitoring & Logs
Section titled âMonitoring & LogsâApplication Logs
Section titled âApplication Logsâ# View Coolify logsdocker logs your-container-name
# View real-time logsdocker logs -f your-container-nameDatabase Monitoring
Section titled âDatabase Monitoringâ# Check database performancenpx prisma studioNext Steps
Section titled âNext StepsâAfter successful installation:
- Configure Entities - Set up your content structure
- Setup Permissions - Configure user roles
- Install Frontend - Deploy your client site
Maintenance
Section titled âMaintenanceâRegular Tasks
Section titled âRegular Tasksâ- Weekly: Check application logs and performance
- Monthly: Update dependencies and security patches
- Quarterly: Database maintenance and optimization
- Annually: Rotate API keys and certificates