本地运行只需要两样东西:Linux 或 macOS 环境、以及对应架构的发布包。数据库可在安装时选择 SQLite 或 MySQL;本文以 SQLite 为例。
1. 解压发布包
mkdir -p ~/djm-cms
cd ~/djm-cms
unzip djm-cms_1.0.153_linux_amd64_update.zip
ls releases/1.0.153
2. 建立目录与配置
cd ~/djm-cms
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/
创建 shared/configs/app.yaml:
app:
environment: production
server:
addr: "127.0.0.1:23180"
admin_path: /manage-local
database:
driver: sqlite
path: storage/database/djm.sqlite
prefix: djm_
生产环境还需要为 auth、comment、member 配置 Base64 随机密钥;其中 auth.identity_hash_key 必须是 32 字节。
3. 执行安装
export DJM_CONFIG=$PWD/shared/configs/app.yaml
./current/bin/cms install \
-site-name "DJM CMS" \
-site-domain localhost \
-admin-path /manage-local \
-admin-user admin \
-admin-password-file /tmp/admin-password.txt
管理员密码文件权限必须是 0600,否则安装命令会拒绝执行。
4. 启动并验证
./current/bin/cms serve
另开一个终端检查:
curl -fsS http://127.0.0.1:23180/health/live
curl -fsS http://127.0.0.1:23180/health/ready
ls -lh storage/database/djm.sqlite
浏览器访问 http://127.0.0.1:23180/ 可以看到站点首页,访问后台入口登录。数据库文件已经生成在 storage/database/,后续备份只需要复制它。
5. 常见问题
第一次启动时,最常见的问题是数据库目录权限和后台入口。下面两条命令可以先做一次自检:
# 确认数据库目录与文件属于运行用户
chown -R www:www shared/storage
ls -ld shared/storage/database
# 后台入口以 app.yaml 中的 server.admin_path 为准
grep admin_path shared/configs/app.yaml
如果 /health/ready 返回 500,先查看应用日志里的数据库路径;后台入口访问不到时,确认地址末尾带斜杠,并检查是否误用了系统保留路径 /admin。
讨论