#}

Deployment Guide

Deploy your GEMVC API to production with Docker, VPS, or cloud platforms

Deployment Guide

Overview

GEMVC supports multiple deployment options: Docker (recommended), VPS with OpenSwoole, or traditional Apache hosting.

Docker

Recommended

VPS + OpenSwoole

High Performance

Apache/Nginx

Traditional

1. Docker Deployment (Recommended)

GEMVC includes a production-ready Docker setup:

Docker Deployment
# Clone your project
git clone https://github.com/your/project.git
cd project

# Copy environment file
cp .env.example .env

# Edit .env with production values
nano .env

# Build and start containers
docker compose up -d --build
Tip: The included docker-compose.yml sets up OpenSwoole, MySQL, and Redis automatically.

2. Production Environment

.env Production
# .env - Production settings
APP_ENV=production
SWOOLE_DISPLAY_ERRORS=0

# Database
DB_HOST=db
DB_NAME=gemvc_production
DB_USER=gemvc
DB_PASSWORD=your-strong-password
DB_ENHANCED_CONNECTION=1

# JWT
TOKEN_SECRET=your-very-long-random-secret-key-minimum-32-chars
TOKEN_ISSUER=YourCompany

# Redis (optional but recommended)
REDIS_HOST=redis
REDIS_PORT=6379

3. VPS Deployment with Traefik

For VPS deployment with automatic SSL:

VPS Setup
# Install Docker on VPS
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Setup Traefik for reverse proxy + SSL
# See: /docs/getting-started/deployment/vps-openswoole-and-traefik

Traefik Benefits:

  • β€’ Automatic Let's Encrypt SSL certificates
  • β€’ Zero-downtime deployments
  • β€’ Load balancing
  • β€’ Automatic HTTPS redirect

4. Database Migration

Database Setup
# Initialize database
php vendor/bin/gemvc db:init

# Run migrations
php vendor/bin/gemvc db:migrate UserTable
php vendor/bin/gemvc db:migrate ProductTable

# List all tables
php vendor/bin/gemvc db:list

5. CI/CD with GitHub Actions

GitHub Actions
# .github/workflows/deploy.yml
name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Deploy via SSH
        uses: appleboy/ssh-action@master
        with:
          host: \${{ secrets.SERVER_HOST }}
          username: \${{ secrets.SERVER_USER }}
          key: \${{ secrets.SSH_KEY }}
          script: |
            cd /var/www/api
            git pull origin main
            docker compose up -d --build
info: Store sensitive data like SSH keys and passwords in GitHub Secrets, not in your code!

Deployment Checklist

  • APP_ENV=production - Disable debug mode
  • Strong TOKEN_SECRET - At least 32 random characters
  • SWOOLE_DISPLAY_ERRORS=0 - Hide errors from users
  • SSL/HTTPS enabled - Use Traefik or Certbot
  • Database backups - Configure automated backups
  • Firewall configured - Only expose necessary ports

Next Steps