宝塔面板部署 DJM CMS:数据库可选、Nginx 与进程守护

安装时选择 SQLite 或 MySQL,从解压到宝塔 Go 项目守护,完整走一遍生产部署。

这篇教程按“程序目录 → SQLite 配置 → 守护 → 反向代理”的顺序完成生产部署。示例使用目录 /www/wwwroot/cms.example.com 和端口 23280,选择 SQLite 时不需要安装 MySQL;选择 MySQL 时,把数据库配置替换为连接信息即可。

1. 解压发布包

mkdir -p /www/wwwroot/cms.example.com/releases
cd /tmp
unzip djm-cms_1.0.153_linux_amd64_update.zip
mv releases/1.0.153 /www/wwwroot/cms.example.com/releases/

cd /www/wwwroot/cms.example.com
ln -s releases/1.0.153 current
mkdir -p shared/configs shared/storage shared/logs shared/plugins shared/themes
ln -s shared/configs configs
ln -s shared/storage storage
ln -s shared/plugins plugins
ln -s shared/themes themes
cp -a releases/1.0.153/themes/. shared/themes/

2. 写入 SQLite 配置

server:
  addr: "127.0.0.1:23280"
  admin_path: /manage-xxxxxxxx
database:
  driver: sqlite
  path: storage/database/djm.sqlite
  prefix: djm_

再创建 shared/configs/runtime.env:

export DJM_CONFIG=/www/wwwroot/cms.example.com/shared/configs/app.yaml

SQLite 模式不需要数据库密码,所以这个文件只有一个配置路径。注意 auth.identity_hash_key 要使用 Base64 编码的 32 字节随机值;配置文档允许 32–64 字节,但插件宿主只接受 32 字节,超出会报 invalid plugin secret key。

3. 执行安装并设置权限

chown -R www:www /www/wwwroot/cms.example.com
chmod 600 shared/configs/app.yaml shared/configs/runtime.env

su -s /bin/bash www -c 'cd /www/wwwroot/cms.example.com && \
  source shared/configs/runtime.env && \
  ./current/bin/cms install -site-name "DJM CMS" \
  -site-domain cms.example.com -admin-path /manage-xxxxxxxx \
  -admin-user admin -admin-password-file /tmp/admin-password.txt'

安装完成后确认数据库文件属于 www:

ls -lh shared/storage/database/djm.sqlite

4. 用宝塔 Go 项目守护

  • 项目名称:djmcms
  • 项目执行文件:/www/wwwroot/cms.example.com/djm-cms(稳定启动器)
  • 执行命令:/www/wwwroot/cms.example.com/djm-cms serve
  • 项目端口:23280,运行用户 www
  • 环境变量文件:/www/wwwroot/cms.example.com/shared/configs/runtime.env
  • 开机启动:开启

不要绕过宝塔进程管理器手动 nohup 启动,否则会出现游离进程占用端口、面板显示异常的问题。

5. 验证

curl -fsS http://127.0.0.1:23280/health/live
curl -fsS http://127.0.0.1:23280/health/ready
ss -lntp | grep 23280

最后把域名解析到服务器,按下一篇教程配置反向代理与 HTTPS。

继续阅读

安装部署 升级后自动重启:systemd 与脚本托管配置 安装部署 让 AI 帮你部署 DJM CMS 安装部署 SQLite 部署与备份:安装时选择单文件数据库 安装部署 反向代理、HTTPS 与健康检查 安装部署 版本升级、回滚与备份

讨论