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 | miniprogram-demo/ |
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 | java -version |
2. Install Missing Components
Ubuntu/Debian:
1 | sudo apt update |
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 | CREATE USER demo WITH PASSWORD 'your_secure_password'; |
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 | server: |
6. Build JAR Package
1 | cd ~/work/code/miniprogram-demo/backend |
Output: backend/target/miniprogram-demo-1.0.0-SNAPSHOT.jar
7. Upload to Server
1 | scp backend/target/miniprogram-demo-1.0.0-SNAPSHOT.jar user@server:/opt/demo/ |
8. Create Systemd Service (Recommended)
1 | sudo vim /etc/systemd/system/demo.service |
1 | [Unit] |
Start the service:
1 | sudo systemctl daemon-reload |
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 | sudo apt install certbot python3-certbot-nginx |
10. Configure Nginx Reverse Proxy
1 | sudo vim /etc/nginx/sites-available/demo |
1 | server { |
Enable and reload:
1 | sudo ln -s /etc/nginx/sites-available/demo /etc/nginx/sites-enabled/ |
Part 5: WeChat Mini Program Configuration
12. Update Backend URL
Edit miniprogram/app.js:
1 | globalData: { |
13. Configure Server Domains
Log into WeChat Official Platform:
- Development Management β Development Settings β Server Domains
- Add
https://your-domain.comto 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 | wechat: |
Restart backend:
1 | sudo systemctl restart demo |
Part 6: Publish Mini Program
15. Upload via Developer Tools
- Open WeChat Developer Tools
- Import the
miniprogram/directory - Enter the correct AppID
- Test all features
- Click Upload button
- Fill in version number and description
16. Submit for Review
- Log into WeChat Official Platform
- Go to Version Management
- Find the uploaded development version
- Click Submit for Review
- Wait 1-3 business days
- 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
baseUrlset 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:
- Check PostgreSQL status:
sudo systemctl status postgresql - Verify username/password
- 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:
- Domain must be ICP-filed and support HTTPS
- Keep production config separate from Git
- Use systemd for auto-restart
- Test thoroughly on real devices
- Renew SSL certificates regularly