iDrv5-MyFR8 Standalone Deployment Guide
This guide explains how to deploy the iDrv5-MyFR8 application on third-party servers instead of Replit.
This guide explains how to deploy the iDrv5-MyFR8 application on third-party servers instead of Replit.
Overview
Section titled “Overview”The standalone deployment package includes:
main_standalone.py- Standalone application entry pointconfig_standalone.py- Third-party server configurationDockerfile.standalone- Docker containerizationdocker-compose.standalone.yml- Multi-container orchestrationdeploy_standalone.sh- Automated deployment scriptgunicorn.conf.py- Production WSGI server configuration
Quick Start
Section titled “Quick Start”Option 1: One-Command Deployment (Recommended)
Section titled “Option 1: One-Command Deployment (Recommended)”# Download and run the deployment scriptcurl -sSL https://raw.githubusercontent.com/your-org/idrv5-myfr8/main/deploy_standalone.sh | bash -s -- \ -d your-domain.com \ -e admin@your-domain.com \ -p SecurePassword123 \ -m docker \ -sOption 2: Docker Compose Deployment
Section titled “Option 2: Docker Compose Deployment”# Clone repositorygit clone https://github.com/your-org/idrv5-myfr8.gitcd idrv5-myfr8
# Copy environment templatecp .env.example .env
# Edit environment variablesnano .env
# Start servicesdocker-compose -f docker-compose.standalone.yml up -dOption 3: Manual Deployment
Section titled “Option 3: Manual Deployment”# Download deployment scriptwget https://raw.githubusercontent.com/your-org/idrv5-myfr8/main/deploy_standalone.sh
# Make executablechmod +x deploy_standalone.sh
# Run deployment./deploy_standalone.sh -d your-domain.com -e admin@your-domain.com -p SecurePassword123 -m manualDeployment Methods
Section titled “Deployment Methods”1. Docker Deployment (Recommended)
Section titled “1. Docker Deployment (Recommended)”Advantages:
- Isolated environment
- Easy scaling
- Consistent deployment
- Automatic dependency management
Requirements:
- Docker 20.10+
- Docker Compose 2.0+
- 4GB RAM minimum
- 20GB storage minimum
Steps:
- Install Docker and Docker Compose
- Copy application files
- Configure environment variables
- Run
docker-compose up -d
2. Manual Deployment
Section titled “2. Manual Deployment”Advantages:
- Full control over environment
- Direct system access
- Custom optimization possible
Requirements:
- Ubuntu 20.04+ or CentOS 8+
- Python 3.11+
- PostgreSQL 14+
- Nginx
- 4GB RAM minimum
Steps:
- Install system dependencies
- Create Python virtual environment
- Install application dependencies
- Configure database
- Setup systemd service
- Configure Nginx reverse proxy
3. Systemd Service Deployment
Section titled “3. Systemd Service Deployment”Advantages:
- System integration
- Automatic startup
- Process management
- Logging integration
Requirements:
- Systemd-based Linux distribution
- Root access for service creation
- PostgreSQL database
Environment Configuration
Section titled “Environment Configuration”Required Environment Variables
Section titled “Required Environment Variables”# Security (Required)SESSION_SECRET=your_32_character_secret_key_hereJWT_SECRET_KEY=your_32_character_jwt_secret_here
# Database (Required)DATABASE_URL=postgresql://user:password@host:5432/databaseDB_PASSWORD=your_secure_database_password
# Application (Required)SYSTEM_NAME=iDrv5-MyFR8COMPANY_NAME=MyFR8 LogisticsSERVER_NAME=your-domain.comOptional Environment Variables
Section titled “Optional Environment Variables”# External ServicesTWILIO_ACCOUNT_SID=your_twilio_account_sidTWILIO_AUTH_TOKEN=your_twilio_auth_tokenSENDGRID_API_KEY=your_sendgrid_api_keyOPENAI_API_KEY=your_openai_api_key
# PerformanceGUNICORN_WORKERS=4GUNICORN_WORKER_CLASS=geventGUNICORN_TIMEOUT=30
# Feature FlagsENABLE_RATE_LIMITING=TrueENABLE_CACHING=TrueENABLE_COMPRESSION=TrueDatabase Setup
Section titled “Database Setup”PostgreSQL Installation
Section titled “PostgreSQL Installation”Ubuntu/Debian:
sudo apt updatesudo apt install postgresql postgresql-contribsudo systemctl start postgresqlsudo systemctl enable postgresqlCentOS/RHEL:
sudo dnf install postgresql postgresql-server postgresql-contribsudo postgresql-setup --initdbsudo systemctl start postgresqlsudo systemctl enable postgresqlDatabase Configuration
Section titled “Database Configuration”# Create database and usersudo -u postgres psqlCREATE USER myfr8_user WITH PASSWORD 'secure_password';CREATE DATABASE idrv5_myfr8 OWNER myfr8_user;GRANT ALL PRIVILEGES ON DATABASE idrv5_myfr8 TO myfr8_user;ALTER USER myfr8_user CREATEDB;\q
# Import database schemaPGPASSWORD=secure_password psql -U myfr8_user -h localhost -d idrv5_myfr8 -f exports/complete_database_export_fixed.sqlSecurity Configuration
Section titled “Security Configuration”SSL Certificate Setup
Section titled “SSL Certificate Setup”Let’s Encrypt (Recommended):
sudo apt install certbot python3-certbot-nginxsudo certbot --nginx -d your-domain.comManual Certificate:
# Copy certificate filessudo cp your-certificate.crt /etc/nginx/ssl/sudo cp your-private-key.key /etc/nginx/ssl/sudo chmod 600 /etc/nginx/ssl/*Firewall Configuration
Section titled “Firewall Configuration”sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow sshsudo ufw allow 80/tcpsudo ufw allow 443/tcpsudo ufw enablePerformance Optimization
Section titled “Performance Optimization”Nginx Configuration
Section titled “Nginx Configuration”server { listen 80; server_name your-domain.com; return 301 https://$server_name$request_uri;}
server { listen 443 ssl http2; server_name your-domain.com;
ssl_certificate /etc/nginx/ssl/your-certificate.crt; ssl_certificate_key /etc/nginx/ssl/your-private-key.key;
# Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
# Static files location /static/ { alias /opt/idrv5-myfr8/static/; expires 30d; add_header Cache-Control "public, no-transform"; }
# Main application 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; proxy_redirect off; proxy_buffering off; }}Gunicorn Optimization
Section titled “Gunicorn Optimization”import multiprocessing
workers = multiprocessing.cpu_count() * 2 + 1worker_class = 'gevent'worker_connections = 1000max_requests = 1000max_requests_jitter = 50preload_app = TrueMonitoring and Maintenance
Section titled “Monitoring and Maintenance”Health Checks
Section titled “Health Checks”# Application healthcurl -f http://localhost:5000/health
# Database healthpg_isready -U myfr8_user -d idrv5_myfr8
# Service statussystemctl status idrv5-myfr8Log Management
Section titled “Log Management”# Application logsjournalctl -u idrv5-myfr8 -f
# Nginx logstail -f /var/log/nginx/access.logtail -f /var/log/nginx/error.log
# Database logstail -f /var/log/postgresql/postgresql-*.logBackup Strategy
Section titled “Backup Strategy”# Database backuppg_dump -U myfr8_user -h localhost idrv5_myfr8 > backup_$(date +%Y%m%d_%H%M%S).sql
# Application backuptar -czf app_backup_$(date +%Y%m%d_%H%M%S).tar.gz /opt/idrv5-myfr8/Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”-
Database Connection Failed
- Check PostgreSQL service status
- Verify database credentials
- Ensure database exists
-
Permission Denied
- Check file ownership and permissions
- Verify user has correct privileges
- Review systemd service configuration
-
SSL Certificate Issues
- Verify certificate files exist
- Check certificate validity
- Ensure proper Nginx configuration
-
Port Already in Use
- Check for existing services on port 5000
- Modify port configuration if needed
- Restart services in correct order
Debug Commands
Section titled “Debug Commands”# Check service statussystemctl status idrv5-myfr8
# View service logsjournalctl -u idrv5-myfr8 -n 100
# Test database connectionPGPASSWORD=your_password psql -U myfr8_user -h localhost -d idrv5_myfr8 -c "SELECT 1;"
# Test application directlycd /opt/idrv5-myfr8source venv/bin/activatepython main_standalone.pySupport
Section titled “Support”For deployment issues:
- Check logs for error messages
- Verify all environment variables are set
- Ensure database is accessible
- Check firewall and network configuration
- Review service status and dependencies
Migration from Replit
Section titled “Migration from Replit”To migrate from Replit to standalone deployment:
- Export database using
pg_dump - Copy application files
- Update configuration for new environment
- Deploy using one of the methods above
- Import database schema and data
- Update DNS to point to new server
- Test all functionality
The standalone deployment maintains full compatibility with the Replit version while providing better performance and control for production environments.