Complete Guide to Deploying WeChat Mini Program: From Server Setup to Launch

After developing a WeChat Mini Program, how to deploy it is the first challenge many developers face. This article provides a detailed walkthrough of deploying a typical WeChat Mini Program project (frontend + SpringBoot backend + PostgreSQL database) from server environment preparation to final launch.

Project Architecture

This article uses the miniprogram-demo project as an example, with the following structure:

1
2
3
4
5
6
7
8
9
10
11
miniprogram-demo/
β”œβ”€β”€ miniprogram/ # WeChat Mini Program Frontend
β”‚ β”œβ”€β”€ app.js # Entry point
β”‚ β”œβ”€β”€ app.json # Configuration
β”‚ β”œβ”€β”€ pages/ # Pages
β”‚ └── utils/ # Utilities
β”œβ”€β”€ backend/ # SpringBoot Backend
β”‚ β”œβ”€β”€ src/
β”‚ └── pom.xml
└── docs/
└── sql/ # Database initialization scripts

Tech Stack:

  • Frontend: Native WeChat Mini Program
  • Backend: SpringBoot 2.7 + MyBatis-Plus
  • Database: PostgreSQL
  • Deployment: Nginx + HTTPS

Part 1: Server Environment Preparation

1. Verify Server Requirements

Deploying a WeChat Mini Program requires:

  • Java 11+ (JDK 17 recommended)
  • PostgreSQL 12+
  • Nginx (for reverse proxy and HTTPS)
  • A domain with ICP filing (mandatory by WeChat)

Check installed components:

1
2
3
java -version
psql --version
nginx -v

2. Install Missing Components

Ubuntu/Debian:

1
2
sudo apt update
sudo apt install openjdk-17-jdk postgresql nginx -y

CentOS/RHEL:

1
sudo yum install java-17-openjdk postgresql-server nginx -y

Part 2: Database Initialization

3. Create Database and User

Log into PostgreSQL:

1
sudo -u postgres psql

Execute the following SQL:

1
2
3
4
CREATE USER demo WITH PASSWORD 'your_secure_password';
CREATE DATABASE demo_db OWNER demo;
GRANT ALL PRIVILEGES ON DATABASE demo_db TO demo;
\q

4. Initialize Database Schema

The project uses Liquibase for database version management. Tables are created automatically on startup. For manual initialization:

1
psql -U demo -d demo_db -f docs/sql/init.sql

Part 3: Backend Deployment

5. Production Configuration

Important: Never commit production config files to Git to avoid leaking sensitive information.

Create config directory on server:

1
mkdir -p /opt/demo/config

Create production config /opt/demo/config/application.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server:
port: 8080

spring:
datasource:
url: jdbc:postgresql://localhost:5432/demo_db
username: demo
password: your_actual_password
driver-class-name: org.postgresql.Driver

wechat:
appid: your_appid
secret: your_appsecret
code2session-url: https://api.weixin.qq.com/sns/jscode2session

jwt:
secret: your_complex_random_secret_key
expiration: 604800000

logging:
level:
com.checkin: info

6. Build JAR Package

1
2
cd ~/work/code/miniprogram-demo/backend
mvn clean package -DskipTests

Output: backend/target/miniprogram-demo-1.0.0-SNAPSHOT.jar

7. Upload to Server

1
2
scp backend/target/miniprogram-demo-1.0.0-SNAPSHOT.jar user@server:/opt/demo/
scp /opt/demo/config/application.yml user@server:/opt/demo/config/
1
sudo vim /etc/systemd/system/demo.service
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=Demo Backend Service
After=postgresql.service

[Service]
User=your_user
WorkingDirectory=/opt/demo
ExecStart=/usr/bin/java -jar /opt/demo/miniprogram-demo-1.0.0-SNAPSHOT.jar --spring.config.location=/opt/demo/config/application.yml
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Start the service:

1
2
3
4
sudo systemctl daemon-reload
sudo systemctl enable demo
sudo systemctl start demo
sudo systemctl status demo

Part 4: HTTPS Configuration

WeChat Mini Programs require HTTPS for all backend APIs.

9. Obtain SSL Certificate

Option 1: Let’s Encrypt (Free, Recommended)

1
2
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com

10. Configure Nginx Reverse Proxy

1
sudo vim /etc/nginx/sites-available/demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
server {
listen 443 ssl;
server_name your-domain.com;

ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
proxy_pass http://127.0.0.1:8080;
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;
}
}

server {
listen 80;
server_name your-domain.com;
return 301 https://$host$request_uri;
}

Enable and reload:

1
2
3
sudo ln -s /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Part 5: WeChat Mini Program Configuration

12. Update Backend URL

Edit miniprogram/app.js:

1
2
3
4
5
globalData: {
baseUrl: 'https://your-domain.com', // Use HTTPS
token: '',
userInfo: null
}

13. Configure Server Domains

Log into WeChat Official Platform:

  • Development Management β†’ Development Settings β†’ Server Domains
  • Add https://your-domain.com to Valid request domains

Requirements:

  • Domain must have ICP filing
  • Domain must support HTTPS

14. Get AppID and Secret

In WeChat Official Platform:

  • Development Management β†’ Development Settings β†’ Developer ID
  • Copy AppID and AppSecret

Add them to backend config:

1
2
3
wechat:
appid: wx1234567890abcdef
secret: your_appsecret_here

Restart backend:

1
sudo systemctl restart demo

Part 6: Publish Mini Program

15. Upload via Developer Tools

  1. Open WeChat Developer Tools
  2. Import the miniprogram/ directory
  3. Enter the correct AppID
  4. Test all features
  5. Click Upload button
  6. Fill in version number and description

16. Submit for Review

  1. Log into WeChat Official Platform
  2. Go to Version Management
  3. Find the uploaded development version
  4. Click Submit for Review
  5. Wait 1-3 business days
  6. After approval, click Publish

Part 7: Verification Checklist

  • PostgreSQL running, database accessible
  • Backend service running (systemctl status demo)
  • HTTPS accessible (curl https://your-domain.com/)
  • Server domains configured in WeChat backend
  • Mini program baseUrl set to HTTPS domain
  • AppID and Secret correctly configured
  • Local testing passed
  • Real device testing passed
  • Mini program uploaded, reviewed, and published

FAQ

Q1: β€œNot in valid request domain list” error

Solution: Add your domain in WeChat Official Platform β†’ Development Settings β†’ Server Domains.

Q2: Database connection failure on startup

Troubleshooting:

  1. Check PostgreSQL status: sudo systemctl status postgresql
  2. Verify username/password
  3. Verify database exists: psql -U postgres -l | grep demo_db

Q3: wx.getUserProfile deprecated

Solution: Use the profile filling component instead. See WeChat docs.

Q4: Low server memory (2GB instance)

Tips:

  • PostgreSQL + Java need ~800MB-1.2GB
  • Configure Swap: sudo fallocate -l 2G /swapfile && sudo mkswap /swapfile && sudo swapon /swapfile
  • Set JVM params: -Xmx512m -Xms256m

Summary

Deploying a WeChat Mini Program involves multiple steps: server setup, database config, backend deployment, HTTPS, Mini Program config, and final release. Follow the steps carefully and you’ll be live.

Key Points:

  1. Domain must be ICP-filed and support HTTPS
  2. Keep production config separate from Git
  3. Use systemd for auto-restart
  4. Test thoroughly on real devices
  5. Renew SSL certificates regularly
Menu