Skip to content

Latest commit

 

History

History
278 lines (221 loc) · 5.38 KB

File metadata and controls

278 lines (221 loc) · 5.38 KB

Deployment Guide for Grace London Team Management System

Prerequisites

  1. Server Requirements:

    • Ubuntu 20.04+ or similar Linux distribution
    • Node.js 18+ and npm
    • PostgreSQL 12+
    • At least 1GB RAM
    • Domain name (optional but recommended)
  2. Local Requirements:

    • Git installed on your local machine
    • SSH access to your server

Step 1: Server Setup

Install Node.js

# Update system
sudo apt update && sudo apt upgrade -y

# Install Node.js 20
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# Verify installation
node --version
npm --version

Install PostgreSQL

# Install PostgreSQL
sudo apt install postgresql postgresql-contrib -y

# Start and enable PostgreSQL
sudo systemctl start postgresql
sudo systemctl enable postgresql

# Create database and user
sudo -u postgres psql

In PostgreSQL shell:

CREATE DATABASE graceteam;
CREATE USER graceuser WITH ENCRYPTED PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE graceteam TO graceuser;
\q

Install PM2 (Process Manager)

sudo npm install -g pm2

Step 2: Deploy Application

Clone and Setup

# Clone your repository (or upload files)
git clone <your-repo-url> graceteam
cd graceteam

# Install dependencies
npm install

# Build the application
npm run build

Environment Configuration

Create a .env file:

nano .env

Add these variables:

NODE_ENV=production
PORT=5000
DATABASE_URL=postgresql://graceuser:your_secure_password@localhost/graceteam
SESSION_SECRET=your_very_long_random_session_secret
SENDGRID_API_KEY=your_sendgrid_api_key_if_you_have_one

Database Setup

# Push database schema
npm run db:push

Step 3: Production Configuration

Create Production Start Script

Create ecosystem.config.js:

module.exports = {
  apps: [{
    name: 'graceteam',
    script: 'server/index.ts',
    interpreter: 'npx',
    interpreter_args: 'tsx',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
      NODE_ENV: 'production',
      PORT: 5000
    }
  }]
};

Start with PM2

# Start the application
pm2 start ecosystem.config.js

# Save PM2 configuration
pm2 save

# Setup PM2 to start on boot
pm2 startup
# Follow the command it provides

Step 4: Web Server Setup (Nginx)

Install Nginx

sudo apt install nginx -y

Configure Nginx

sudo nano /etc/nginx/sites-available/graceteam

Add this configuration:

server {
    listen 80;
    server_name your-domain.com www.your-domain.com;

    location / {
        proxy_pass http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

Enable the site

# Enable the site
sudo ln -s /etc/nginx/sites-available/graceteam /etc/nginx/sites-enabled/

# Test nginx configuration
sudo nginx -t

# Restart nginx
sudo systemctl restart nginx

Step 5: SSL Certificate (Optional but Recommended)

Install Certbot

sudo apt install certbot python3-certbot-nginx -y

Get SSL Certificate

sudo certbot --nginx -d your-domain.com -d www.your-domain.com

Step 6: Firewall Setup

# Allow SSH, HTTP, and HTTPS
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable

Step 7: Monitoring and Maintenance

Check Application Status

# Check PM2 status
pm2 status

# View logs
pm2 logs graceteam

# Restart if needed
pm2 restart graceteam

Database Backup Script

Create backup.sh:

#!/bin/bash
DATE=$(date +%Y%m%d_%H%M%S)
pg_dump -U graceuser -h localhost graceteam > /home/backup/graceteam_$DATE.sql
# Keep only last 7 days of backups
find /home/backup -name "graceteam_*.sql" -mtime +7 -delete

Make it executable and add to cron:

chmod +x backup.sh
crontab -e
# Add: 0 2 * * * /path/to/backup.sh

Troubleshooting

Common Issues:

  1. Port already in use:

    sudo lsof -i :5000
    sudo kill -9 <PID>
  2. Database connection issues:

    • Check PostgreSQL is running: sudo systemctl status postgresql
    • Verify credentials in .env file
    • Check database exists: sudo -u postgres psql -l
  3. Permission issues:

    sudo chown -R $USER:$USER /path/to/graceteam
  4. Application not starting:

    pm2 logs graceteam

Security Recommendations

  1. Change default passwords
  2. Keep system updated: sudo apt update && sudo apt upgrade
  3. Use strong session secrets
  4. Regular backups
  5. Monitor logs: pm2 logs
  6. Use fail2ban: sudo apt install fail2ban

Updates

To update the application:

# Pull latest changes
git pull origin main

# Install any new dependencies
npm install

# Restart application
pm2 restart graceteam

Your application will be accessible at:

  • HTTP: http://your-domain.com or http://your-server-ip
  • HTTPS: https://your-domain.com (if SSL configured)

The super admin login will be available at /login with automatic privileges as configured in your application.