# Backend Separation Deployment This guide will help you independently deploy the PPanel backend service, suitable for front-end and back-end separation deployment scenarios. ## Overview Backend separation deployment allows you to deploy the PPanel backend service on an independent server to provide API services for frontend applications. This deployment method has the following advantages: - 🚀 Independently scale backend service performance - 🔒 Better security isolation - 🌐 Support multiple frontend instances connecting to the same backend - 🛠️ Facilitate independent maintenance and upgrades of backend services ## System Requirements ### Minimum Configuration - CPU: 1 core - Memory: 1 GB - Storage: 10 GB - OS: Linux (Ubuntu 20.04+, Debian 11+, CentOS 8+ recommended) ### Recommended Configuration - CPU: 2+ cores - Memory: 2+ GB - Storage: 20+ GB ## Deployment Methods ### Method 1: Docker Deployment (Recommended) #### 1. Install Docker ```bash # Ubuntu/Debian curl -fsSL https://get.docker.com | sh # Start Docker service sudo systemctl start docker sudo systemctl enable docker ``` #### 2. Create Configuration File Create backend config file `config.yaml`: ```yaml # Database configuration database: type: mysql host: localhost port: 3306 username: ppanel password: your_password database: ppanel # Redis configuration redis: host: localhost port: 6379 password: "" db: 0 # Server configuration server: host: 0.0.0.0 port: 8080 # CORS configuration (Important: allow frontend domain access) cors: allow_origins: - "https://your-frontend-domain.com" - "http://localhost:3000" # Development environment allow_methods: - GET - POST - PUT - DELETE - OPTIONS allow_headers: - "*" # JWT configuration jwt: secret: "your-secret-key" expire: 7200 # 2 hours # API configuration api: prefix: "/api" version: "v1" ``` #### 3. Prepare MySQL Database ```bash # Run MySQL with Docker docker run -d \ --name ppanel-mysql \ -e MYSQL_ROOT_PASSWORD=root_password \ -e MYSQL_DATABASE=ppanel \ -e MYSQL_USER=ppanel \ -e MYSQL_PASSWORD=your_password \ -p 3306:3306 \ -v ppanel-mysql-data:/var/lib/mysql \ mysql:8.0 # Wait for MySQL to start sleep 10 ``` #### 4. Prepare Redis ```bash # Run Redis with Docker docker run -d \ --name ppanel-redis \ -p 6379:6379 \ -v ppanel-redis-data:/data \ redis:7-alpine ``` #### 5. Run Backend Service ```bash # Pull backend image docker pull ghcr.io/perfect-panel/ppanel:latest # Run backend container docker run -d \ --name ppanel-backend \ -p 8080:8080 \ -v $(pwd)/config.yaml:/app/config.yaml \ --link ppanel-mysql:mysql \ --link ppanel-redis:redis \ ghcr.io/perfect-panel/ppanel:latest ``` #### 6. Initialize Database ```bash # Execute database migration docker exec ppanel-backend ./ppanel migrate ``` ### Method 2: Binary Deployment #### 1. Download Backend Program ```bash # Download latest version wget https://github.com/perfect-panel/ppanel/releases/latest/download/ppanel-linux-amd64.tar.gz # Extract tar -xzf ppanel-linux-amd64.tar.gz cd ppanel # Grant execute permission chmod +x ppanel ``` #### 2. Configure Backend Service Create config file `config.yaml` (same content as Docker deployment method). #### 3. Install and Configure MySQL ```bash # Ubuntu/Debian sudo apt update sudo apt install mysql-server -y # Create database and user sudo mysql < backup.sql # Remove old container docker rm ppanel-backend # Run new container docker run -d \ --name ppanel-backend \ -p 8080:8080 \ -v $(pwd)/config.yaml:/app/config.yaml \ --link ppanel-mysql:mysql \ --link ppanel-redis:redis \ ghcr.io/perfect-panel/ppanel:latest # Execute database migration docker exec ppanel-backend ./ppanel migrate ``` ### Binary Upgrade ```bash # Stop service sudo systemctl stop ppanel # Backup old version sudo cp /opt/ppanel/ppanel /opt/ppanel/ppanel.backup # Download new version wget https://github.com/perfect-panel/ppanel/releases/latest/download/ppanel-linux-amd64.tar.gz tar -xzf ppanel-linux-amd64.tar.gz # Replace file sudo mv ppanel /opt/ppanel/ sudo chown ppanel:ppanel /opt/ppanel/ppanel # Execute database migration cd /opt/ppanel sudo -u ppanel ./ppanel migrate # Start service sudo systemctl start ppanel ``` ## Next Steps - [Frontend Separation Deployment](./frontend.md) - Deploy frontend application - [Node Agent Installation](../node/installation.md) - Deploy node service - [API Documentation](/api/reference) - View complete API documentation