Source code compilation installation of AnQi CMS
Eligible Audience: Developers who need secondary development, customization features, or official binary packages that cannot meet their needs.
Difficulty: ⭐⭐⭐⭐ (requires familiarity with GoLang and command line operations)
Prerequisites
| Software | Version requirements | Description |
|---|---|---|
| GoLang | 1.13+ (recommended 1.25+) | Compile Go source code |
| Git | Any version | Clone code repository |
| MySQL | 5.6.35+ | Run database |
If GoLang has not been installed yet, please visithttps://go.dev/dl/Download and install.
Get the source code
# 从 GitHub 克隆(推荐)
git clone https://github.com/fesiong/anqicms.git
# 或从 GitCode 镜像(国内用户)
git clone https://gitcode.com/anqicms/anqicms.git
# 进入项目目录
cd anqicms
Compile preparation
Set up Go proxy (for domestic users)
go env -w GOPROXY=https://goproxy.cn,direct
Download dependencies
go mod tidy
go mod vendor
Compile executable file
Method 1: Test run (does not generate binary file)
# 直接运行源码,用于调试和测试
go run kandaoni.com/anqicms/main
After running, visit the browserhttp://127.0.0.1:8001to see the effect.
Method two: Generate binary file
Windows system:
go build -ldflags '-w -s -H=windowsgui' -o ./anqicms.exe kandaoni.com/anqicms/main
-w -s: Remove debug information, reduce file size-H=windowsgui: Windows GUI mode, command line window is not displayed when running
MacOS system:
go build -ldflags '-w -s' -o ./anqicms kandaoni.com/anqicms/main
Linux system:
Recommended to use the Makefile自带 of the project:
make
After compilation, generate in the root directory of the projectrelease/Directory, which includes the complete running environment (executable files, template files, static resources, etc.):
release/
├── anqicms # 编译好的可执行文件
├── config.sample.json # 配置文件示例
├── template/ # 模板目录
├── public/ # Web 根目录
├── system/ # 后台管理界面
├── locales/ # 多语言包
├── data/ # 数据目录
├── start.sh # 启动脚本
├── stop.sh # 停止脚本
└── doc/ # 开发文档
You can also compile directly:
go build -ldflags '-w -s' -o ./anqicms kandaoni.com/anqicms/main
Cross compilation
Compile for the target platform on different platforms:
# 在 MacOS 上编译 Linux 版本
GOOS=linux GOARCH=amd64 go build -ldflags '-w -s' -o ./anqicms-linux kandaoni.com/anqicms/main
# 在 MacOS 上编译 Windows 版本
GOOS=windows GOARCH=amd64 go build -ldflags '-w -s -H=windowsgui' -o ./anqicms.exe kandaoni.com/anqicms/main
# 在 Linux 上编译 Windows 版本
GOOS=windows GOARCH=amd64 go build -ldflags '-w -s -H=windowsgui' -o ./anqicms.exe kandaoni.com/anqicms/main
GOOSandGOARCHIt is the environment variable for Go cross compilation, specifying the target operating system and CPU architecture.
Compile the backend management interface
Note: If the code is cloned from GitHub, the backend management interface (
system/directory) is empty by default, and needs to be compiled or downloaded separately.
Method one: Download the pre-built package
Fromanqicms-admin ReleasesDownload the latest versionsystem.zipand unzip it into the root directory of the AnQiCMS project.systemFolder.
# 下载 system.zip
wget https://github.com/fesiong/anqicms-admin/releases/latest/download/system.zip
# 解压到 system 目录
unzip system.zip -d system/
Method two: compile manually
If you need to develop the background management interface twice, you can cloneanqicms-adminBuild the repository manually (Vue.js project):
git clone https://github.com/fesiong/anqicms-admin.git
cd anqicms-admin
# 安装依赖
npm install
# 构建
npm run build
# 构建产物在 dist/ 目录,将其复制到 anqicms 根目录下的 system/ 目录
cp -r dist/* /path/to/anqicms/system/
Run the compiled version
# 1. 将编译好的文件复制到目标目录
# 2. 编辑 config.json 配置端口等信息
# 3. 启动
./start.sh
# 或直接运行
./anqicms
# 首次运行会提示初始化,访问 http://127.0.0.1:8001 进入安装界面
Common Makefile commands
Under the project root directoryMakefileProvides convenient build commands:
# 查看所有可用命令
make help
# 编译(生成 release 目录)
make
# 清理编译产物
make clean
# 运行测试
make test
# 查看版本号
make version
❓ Executego run kandaoni.com/anqicms/mainand promptgo: not foundWhat should I do?
The Go language environment is not installed or the environment variables are not configured correctly.
# 检查 Go 是否安装
go version
# 如果输出 "command not found",说明没有安装
# 安装 Go(Ubuntu/Debian 示例)
apt install golang-go
# 或从官网下载最新版
# 访问 https://go.dev/dl/ 下载对应系统的安装包
# 安装后验证
go version
# 应输出类似:go version go1.25.5 linux/amd64
After installing Go, domestic users still need to set up a proxy:
go env -w GOPROXY=https://goproxy.cn,direct
❓ The compiled binary package is very large (hundreds of MB), can it be reduced?
The default compiled binary package includes debugging information and symbol tables, which are large in size. The following methods can significantly reduce the size:
| Method | command | Effect |
|---|---|---|
| Remove debugging information | go build -ldflags '-w -s' |
About 40% reduction |
| UPX compression | upx anqicms |
About 70% reduction |
Complete optimization command:
# 编译时去除调试信息
go build -ldflags '-w -s' -o ./anqicms kandaoni.com/anqicms/main
# 安装 UPX(Ubuntu)
apt install upx
# 压缩二进包
upx anqicms
# 压缩后体积可降至 15-20 MB
After v3.6.1, the official has already optimized the size (from 103 MB to 51 MB), which is also effective when compiling the source code.
❓ How can I confirm that the modifications to the source code have taken effect after compilation?
Several verification methods:
# 方式一:通过版本号验证(如果在代码中修改了版本号)
./anqicms --version
# 方式二:通过编译时间戳验证
ls -la ./anqicms
# 查看文件的修改时间,确认是刚刚编译的
# 方式三:直接验证功能
# 如果你的修改是增加了某个新标签或新接口
# 可以直接在浏览器中访问对应的 URL 确认
# 方式四:校验文件 MD5(前后对比)
md5sum ./anqicms
# 每次编译的 MD5 都不同
Remember: After each modification of the source code, it is necessary to recompile andrestart the AnQiCMS process, the modification will take effect. After restarting, you also need to update the cache in the background.