mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 11:25:49 +00:00
76df944119
- PRODUCTION_DEPLOYMENT.md: Comprehensive production deployment guide - deploy.sh: Master deployment script for backend and frontend - deploy-backend.sh: Automated backend deployment with health checks - deploy-frontend.sh: Automated frontend build and deployment Features: - Automated dependency installation - Database connection verification - Health checks for services - PM2 process management - Backup creation - Multi-environment support (production/staging/local)
10 KiB
10 KiB
OpenLearnX Production Deployment Guide
Last Updated: May 12, 2026
Status: Ready for Production Deployment
📋 Table of Contents
- Prerequisites
- Backend Deployment
- Frontend Deployment
- Environment Configuration
- Database Setup
- Blockchain Setup
- Post-Deployment Checks
- Monitoring & Maintenance
Prerequisites
Required Tools
- Node.js 18+ (for frontend)
- Python 3.10+ (for backend)
- MongoDB 4.4+ (database)
- Foundry/Anvil or Ethereum RPC endpoint (blockchain)
- Git
- PM2 or systemd (process manager)
- Nginx or Apache (reverse proxy)
- SSL/TLS certificates (HTTPS)
Recommended Hosting
- Backend: Heroku, DigitalOcean, AWS, GCP, or self-hosted VPS
- Frontend: Vercel, Netlify, or static hosting
- Database: MongoDB Atlas, AWS DocumentDB, or self-hosted
- Blockchain: Alchemy, Infura, or self-hosted node
Backend Deployment
Option 1: Deploy to Heroku
1. Prerequisites
npm install -g heroku
heroku login
2. Create Procfile
cd backend
cat > Procfile << 'EOF'
web: python main.py
EOF
3. Create requirements file (if not exists)
pip freeze > requirements.txt
4. Deploy to Heroku
heroku create openlearnx-backend
git push heroku main
# Set environment variables
heroku config:set FLASK_ENV=production
heroku config:set MONGODB_URI=<your-mongodb-uri>
heroku config:set WEB3_PROVIDER_URL=<your-rpc-endpoint>
heroku config:set CONTRACT_ADDRESS=<deployed-contract-address>
heroku config:set SECRET_KEY=<secure-random-key>
heroku config:set JWT_SECRET_KEY=<secure-jwt-key>
5. View logs
heroku logs --tail
Option 2: Deploy to VPS (DigitalOcean/AWS/Linode)
1. SSH into server
ssh root@your-server-ip
2. Install dependencies
apt update && apt upgrade -y
apt install -y python3.10 python3-pip python3-venv nginx git mongodb
3. Clone repository
cd /var/www
git clone https://github.com/th30d4y/OpenLearnX.git
cd OpenLearnX/backend
4. Setup Python environment
python3 -m venv venv
source venv/bin/activate
pip install -r ../requirements.txt
5. Create .env file
cat > .env << 'EOF'
FLASK_ENV=production
SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(32))')
MONGODB_URI=mongodb://localhost:27017/openlearnx
WEB3_PROVIDER_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
CONTRACT_ADDRESS=0x...
JWT_SECRET_KEY=$(python3 -c 'import secrets; print(secrets.token_hex(32))')
EOF
6. Setup PM2
npm install -g pm2
pm2 start "python3 main.py" --name openlearnx-backend
pm2 startup
pm2 save
7. Configure Nginx
cat > /etc/nginx/sites-available/openlearnx-backend << 'EOF'
server {
listen 80;
server_name api.openlearnx.com;
location / {
proxy_pass http://127.0.0.1:5000;
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;
}
}
EOF
ln -s /etc/nginx/sites-available/openlearnx-backend /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
8. Setup SSL with Let's Encrypt
apt install -y certbot python3-certbot-nginx
certbot --nginx -d api.openlearnx.com
Frontend Deployment
Option 1: Deploy to Vercel
1. Connect repository to Vercel
- Go to https://vercel.com
- Import GitHub repository
- Select
frontendas root directory
2. Configure environment variables
NEXT_PUBLIC_API_URL=https://api.openlearnx.com
NEXT_PUBLIC_CHAIN_ID=1
NEXT_PUBLIC_CONTRACT_ADDRESS=0x...
NEXT_PUBLIC_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
3. Deploy
git push origin main
# Vercel will automatically deploy on push
Option 2: Deploy to Netlify
1. Connect repository
- Go to https://netlify.com
- Import GitHub repository
- Select
frontendas publish directory
2. Build settings
- Build command:
pnpm install && pnpm build - Publish directory:
.next
3. Environment variables
NEXT_PUBLIC_API_URL=https://api.openlearnx.com
NEXT_PUBLIC_CHAIN_ID=1
NEXT_PUBLIC_CONTRACT_ADDRESS=0x...
NEXT_PUBLIC_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
Option 3: Deploy to VPS
1. SSH into server
ssh root@your-server-ip
2. Install Node.js
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
apt install -y nodejs
npm install -g pnpm
3. Clone repository
cd /var/www
git clone https://github.com/th30d4y/OpenLearnX.git
cd OpenLearnX/frontend
4. Build application
pnpm install
pnpm build
5. Setup PM2
pm2 start "pnpm start" --name openlearnx-frontend
pm2 startup
pm2 save
6. Configure Nginx
cat > /etc/nginx/sites-available/openlearnx-frontend << 'EOF'
server {
listen 80;
server_name openlearnx.com;
location / {
proxy_pass http://127.0.0.1:3000;
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;
}
}
EOF
ln -s /etc/nginx/sites-available/openlearnx-frontend /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
7. Setup SSL
certbot --nginx -d openlearnx.com
Environment Configuration
Backend (.env) - Production
FLASK_ENV=production
DEBUG=False
SECRET_KEY=<secure-random-32-char-key>
JWT_SECRET_KEY=<secure-jwt-key>
# Database
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/openlearnx
# Blockchain
WEB3_PROVIDER_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
CONTRACT_ADDRESS=0x<deployed-contract-address>
# Security
CORS_ORIGINS=https://openlearnx.com,https://www.openlearnx.com
ADMIN_TOKEN=<secure-admin-token>
# Optional: Email configuration
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
Frontend (.env.production.local)
NEXT_PUBLIC_API_URL=https://api.openlearnx.com
NEXT_PUBLIC_CHAIN_ID=1
NEXT_PUBLIC_CONTRACT_ADDRESS=0x<contract-address>
NEXT_PUBLIC_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
Database Setup
MongoDB Atlas (Cloud)
- Go to https://mongodb.com/cloud/atlas
- Create account and new cluster
- Add database user with strong password
- Whitelist IP addresses
- Get connection string:
mongodb+srv://user:pass@cluster.mongodb.net/openlearnx
Self-Hosted MongoDB
# Install MongoDB
apt install -y mongodb-org
# Start service
systemctl start mongod
systemctl enable mongod
# Create database and user
mongosh
use openlearnx
db.createUser({
user: "openlearnx",
pwd: "secure-password",
roles: ["readWrite"]
})
Blockchain Setup
Using Alchemy (Recommended)
- Go to https://alchemy.com
- Create account and new app
- Select Ethereum mainnet (or testnet)
- Get API key:
https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY
Using Infura
- Go to https://infura.io
- Create account and new project
- Select Ethereum mainnet
- Get API key:
https://mainnet.infura.io/v3/YOUR-API-KEY
Self-Hosted Node
# Deploy smart contract to mainnet
cd backend
source venv/bin/activate
# Update WEB3_PROVIDER_URL to mainnet endpoint
python3 scripts/deploy.py # Deploys to mainnet
Post-Deployment Checks
1. Test Backend
curl https://api.openlearnx.com/api/health
curl https://api.openlearnx.com/api/dashboard/comprehensive-stats
2. Test Frontend
- Open https://openlearnx.com in browser
- Verify page loads
- Test wallet connection
- Test authentication flow
3. Database
mongosh
use openlearnx
db.stats()
4. Blockchain
curl -X POST https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0x...","latest"],"id":1}'
Monitoring & Maintenance
PM2 Monitoring
pm2 monit # Real-time monitoring
pm2 logs # View logs
pm2 restart all # Restart all processes
pm2 stop all # Stop all processes
Nginx Logs
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log
Database Backups
# Daily backup to S3
0 2 * * * mongodump --uri="mongodb+srv://..." --archive=/backups/openlearnx-$(date +\%Y\%m\%d).archive
SSL Certificate Renewal
# Auto-renewal with Let's Encrypt
certbot renew --dry-run
certbot renew # Runs automatically via cron
Update dependencies
# Backend
cd backend
source venv/bin/activate
pip install --upgrade pip
pip install -r ../requirements.txt
# Frontend
cd frontend
pnpm update
pnpm build
Troubleshooting
Backend not responding
pm2 logs openlearnx-backend
systemctl status mongod
Frontend blank page
pm2 logs openlearnx-frontend
# Check NEXT_PUBLIC_API_URL environment variable
Database connection errors
# Test MongoDB connection
mongosh --uri="your-connection-string"
SSL certificate issues
certbot renew --force-renewal
systemctl restart nginx
Security Checklist
- Update
SECRET_KEYandJWT_SECRET_KEYwith secure values - Enable HTTPS with SSL certificates
- Configure firewall rules
- Setup rate limiting on API
- Enable CORS only for your domain
- Rotate API keys regularly
- Setup monitoring and alerting
- Implement database backups
- Use environment variables for secrets
- Enable audit logging
- Update dependencies regularly
- Setup DDoS protection (Cloudflare)
Support
For issues or questions:
- GitHub Issues: https://github.com/th30d4y/OpenLearnX/issues
- Documentation: See DOCUMENTATION.md
- Contact: See README.md for contact info
Deployment Version: 2.0.4
Last Updated: May 12, 2026