Ubuntu 22.04 安装 MantisBT 指南

Ubuntu 22.04 安装 MantisBT 2.28.4 全流程实测:LAMP 基础环境、官方 tarball 部署与安装向导、首次登录改密、建项目提单闭环、健康检查、升级与多版本管理,附 Nginx+PHP-FPM 备用方案与 7 个典型报错排障实录。

MantisBTMantisBT工单系统2026/10/21

Ubuntu 22.04 安装 MantisBT 指南

目标:在 Ubuntu 22.04 服务器上从零完成 MantisBT 2.28.4 的安装与业务闭环——LAMP 基础环境、官方 tarball 部署、安装向导、首次登录改密、建项目、提单、健康检查与升级验证全部实测通过;另附 Nginx + PHP-FPM 备用方案与七个典型报错的排障实录。

一、环境信息

  • 操作系统:Ubuntu 22.04(x86_64)
  • MantisBT:2.28.4(官方最新稳定版,官网与 GitHub releases.atom 查询日期 2026-10-21)
  • Web 服务器:Apache 2.4.52(方案 A) / Nginx 1.18.0 + PHP-FPM 8.1(方案 B)
  • 数据库:MariaDB 10.6.23
  • PHP:8.1.2-1ubuntu2.27
  • 部署路径:/var/www/html/mantisbt(方案 A)、/var/www/mantisbt-nginx(方案 B)
  • 访问入口:http://localhost:8132/mantisbt/(本文实验服务器的 Web 对外端口为 8132,方案 B 为 8080)
  • 数据库:方案 A 用 bugtracker,方案 B 用 bugtracker_nginx,专用账号 mantisbt
  • 演示账号:administrator / q1w2e3r4(首次登录后已从默认密码改掉)
  • 官方发行包:mantisbt-2.28.4.tar.gz,sha256 a400bd2957154baad3412130031e893d5c18cf1ed1cfb38b77ee64afd1ed2a33

二、前置条件

安装前需要确认的软件与环境清单:

  • 一台 Ubuntu 22.04 服务器(1C/1G 即可满足最小运行,官方 README 对内存无硬性要求)。
  • 能访问外网或可用的 HTTP 代理(下载发行包约 16 MB)。
  • Apache + PHP(含 mysqli、mbstring、xml、intl、curl、gd 扩展)+ MariaDB,本文在第四节一并安装。
  • 服务器的 8132 端口(方案 A)或 8080 端口(方案 B)未被占用:
ss -ltn | grep -E ':8132|:8080' || echo 端口空闲

实测回显(端口空闲时无输出,|| 分支生效):

端口空闲

三、版本选型说明

3.1 版本线与定版

MantisBT 遵循「大版本 + 维护版」节奏,近期版本发布时间如下(GitHub releases.atom,查询日期 2026-10-21):

版本发布日期说明
2.28.42026-07-01当前最新稳定版(本文采用)
2.28.32026-05-142.28 维护版
2.28.12026-03-162.28 维护版
2.28.02025-12-302.28 大版本
2.27.32025-11-03上一维护线

关键差异:大版本(x.y.0)引入功能与界面变化,维护版(x.y.z)只做缺陷修复与安全响应;生产环境应固定在最新大版本的最新维护版,即 2.28.4。

3.2 依赖兼容矩阵

依赖2.28.4 要求(发行包 README.md 与 core/constant_inc.php)
PHP≥ 7.4.0,无默认上限(Ubuntu 22.04 默认 8.1 实测可用)
数据库MySQL ≥ 5.5.35 / MariaDB 10.x / PostgreSQL ≥ 9.2
PHP 扩展mysqli 必装;mbstring、xml 必装;intl、gd、curl、ldap、soap 可选

3.3 下载渠道

官方下载页 https://mantisbt.org/download.php 当前将 2.28.4 指向 SourceForge 发行目录 mantis-stable/2.28.4/,提供 mantisbt-2.28.4.tar.gz 与 mantisbt-2.28.4.zip 两种格式;GitHub Releases 页为同一产出的镜像渠道。生产安装建议用 tar.gz 并核对 sha256(本文第一节已给出)。

四、方案 A:官方 tarball + Apache + MariaDB 在线安装(主线)

4.1 方案说明

本方案是官方 Admin Guide 的推荐路径:系统源安装 LAMP 基础栈 → 官方 tarball 解压到 Web 根目录 → 跑 Web 安装向导建表。全程无需编译,5 分钟量级可完成。

4.2 安装基础环境

先更新软件源索引,再一次性安装 Apache、MariaDB、PHP 及扩展:

apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 mariadb-server php php-mysql php-mbstring php-xml php-curl php-gd php-intl php-ldap php-zip unzip wget curl

实测输出节选(apt-get update 尾部):

Get:18 http://archive.ubuntu.com/ubuntu jammy-backports/main amd64 Packages [82.9 kB]
Fetched 49.0 MB in 6s (8809 kB/s)
Reading package lists...
done.

安装包尾部实测输出节选(设置触发器阶段):

Processing triggers for php8.1-cli (8.1.2-1ubuntu2.27) ...
Processing triggers for libapache2-mod-php8.1 (8.1.2-1ubuntu2.27) ...

4.3 启动并验证 Web 与数据库服务

Ubuntu 22.04 安装后默认自启;如未启动,手动拉起两个服务:

service mariadb start
service apache2 start

实测输出:

 * Starting MariaDB database server mariadbd
   ...done.
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.89.62.2. Set the 'ServerName' directive globally to suppress this message
 *

⚠️ 注意:AH00558 只是提示(Apache 用探测到的地址代替了 FQDN),服务已正常启动。要消除它,在 /etc/apache2/conf-available/servername.conf 写入 ServerName <你的域名或IP> 后 a2enconf servername 并重启 Apache。

采集三个组件的版本回显,确认安装成功:

mariadb --version
php -v | head -1
apache2 -v | head -1
mysqladmin status | head -1

实测输出:

mariadb  Ver 15.1 Distrib 10.6.23-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
PHP 8.1.2-1ubuntu2.27 (cli) (built: Oct 13 2026 18:55:46) (NTS)
Server version: Apache/2.4.52 (Ubuntu)
Uptime: 4  Threads: 1  Questions: 60  Slow queries: 0  Opens: 33  Open tables: 26  Queries per second avg: 15.000

4.4 创建数据库与专用账号

MantisBT 向导可以顺带建库,但生产实践建议预先建库授权,让向导只用业务账号连库:

mariadb -e "CREATE DATABASE bugtracker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'mantisbt'@'localhost' IDENTIFIED BY 'q1w2e3r4'; GRANT ALL PRIVILEGES ON bugtracker.* TO 'mantisbt'@'localhost'; FLUSH PRIVILEGES; SHOW DATABASES; SELECT User,Host FROM mysql.user;"

实测输出:

Database
bugtracker
information_schema
mysql
performance_schema
sys
User    Host
mantisbt        localhost
mariadb.sys     localhost
mysql   localhost
root    localhost

💡 说明:utf8mb4_unicode_ci 是为中文摘要与表情字符兜底;mantisbt 账号只授予 bugtracker.* 权限,遵循最小权限原则。演示密码 q1w2e3r4 仅用于文档实验,生产请换成强口令。

4.5 下载发行包并部署到 Web 根目录

下载官方 tarball(境内直连 SourceForge 较慢时,可像本文一样加代理参数 -x http://192.168.1.62:7897;无代理环境去掉该参数即可):

cd /var/www/html
wget -x http://192.168.1.62:7897 'https://downloads.sourceforge.net/project/mantisbt/mantis-stable/2.28.4/mantisbt-2.28.4.tar.gz' -O mantisbt-2.28.4.tar.gz

实测输出(尾部):

FINISHED --2026-10-21 07:06:55--
Total wall clock time: 23s
Downloaded: 1 files, 15M in 18s (865 KB/s)

校验完整性并确认大小:

ls -l mantisbt-2.28.4.tar.gz
sha256sum mantisbt-2.28.4.tar.gz

实测输出:

-rw-r--r-- 1 root root 15951667 Jul 13 23:16 mantisbt-2.28.4.tar.gz
a400bd2957154baad3412130031e893d5c18cf1ed1cfb38b77ee64afd1ed2a33  mantisbt-2.28.4.tar.gz

解压、统一目录名、把属主交给 Web 运行用户 www-data:

tar xzf mantisbt-2.28.4.tar.gz
mv mantisbt-2.28.4 mantisbt
chown -R www-data:www-data mantisbt
ls -ld mantisbt

实测输出:

drwx------ 16 www-data www-data 12288 Jul 13 23:14 mantisbt

💡 说明:tarball 内目录权限位是 700,属主是 www-data,Web 服务可正常读写,不影响使用;若希望放宽为常规目录权限,可执行 chmod 755 /var/www/html/mantisbt。

4.6 运行安装向导

浏览器访问 http://localhost:8132/mantisbt/admin/install.php,第 1 步接受许可,第 2 步进入数据库参数表单,字段与本文取值如下:

字段取值说明
Username (db)mantisbt业务账号(4.4 步创建)
Password (db)q1w2e3r4业务账号密码
Database namebugtracker目标库
Admin Username / Passwordmantisbt / q1w2e3r4建表用 DBA 账号;库里已建好,可复用业务账号
Table prefix / Plugin prefix / Suffixmantis / plugin / _table保持默认

点击「Install/Upgrade Database」后,向导逐项自检并建表。等价的无人值守执行方式(curl 直接提交同一表单,便于脚本化):

curl -s -X POST 'http://localhost:8132/mantisbt/admin/install.php' \
  --data 'install=2&hostname=localhost&db_username=mantisbt&db_password=q1w2e3r4&database_name=bugtracker&admin_username=mantisbt&admin_password=q1w2e3r4&db_table_prefix=mantis&db_table_plugin_prefix=plugin&db_table_suffix=_table&go=Install%2FUpgrade+Database'

实测结果页文本(关键行节选;结果页全文共 24 处 GOOD/BAD 状态标记,其中 BAD 为 0):

Attempting to connect to database as admin GOOD
Checking URL to installation POSSIBLE PROBLEM
Can't retrieve web page at 'http://localhost:8132/mantisbt/'.
The system will not function properly if this URL is not accessible.
Attempting to connect to database as user GOOD
Checking Database Server Version
Running mysqli version 10.6.23-MariaDB-0ubuntu0.22.04.1 GOOD
Installing Database
Create database if it does not exist GOOD
Schema step 0: CreateTableSQL
...
checking ability to DELETE records GOOD
Installation Complete
MantisBT was installed successfully. Continue to log in.

⚠️ 注意:POSSIBLE PROBLEM 是向导尝试回访 $g_path 生成的站点 URL 失败的自检提示。本文服务器 Web 端口为 8132,而向导进程内回访用了 80 端口的 localhost,因此报警;只要浏览器能正常打开登录页即可忽略。若部署在反向代理或端口映射后,安装完成后务必核对 config/config_inc.php 里的 $g_path 与真实访问地址一致(详见第九节 Q5)。

4.7 安装结果验证

向导生成了实例配置文件,查看其内容:

cat /var/www/html/mantisbt/config/config_inc.php

实测输出:

<?php
$g_hostname               = 'localhost';
$g_db_type                = 'mysqli';
$g_database_name          = 'bugtracker';
$g_db_username            = 'mantisbt';
$g_db_password            = 'q1w2e3r4';

$g_default_timezone       = 'UTC';

$g_crypto_master_salt     = 'MQskrbUlDb7M+55PKtk7VLtKH44X21FhkbC8trXH0Vk=';

$g_path                   = 'http://localhost:8132/mantisbt/';

逐项说明:$g_hostname/$g_db_type/$g_database_name/$g_db_username/$g_db_password 为数据库连接五要素;$g_default_timezone 为系统时区;$g_crypto_master_salt 是实例级加密盐( Cookie 与令牌哈希依赖它,严禁跨实例复制);$g_path 是系统对外基准 URL,反代/换端口后要改这里。

验证建表数量与默认管理员账号:

mariadb -u mantisbt -pq1w2e3r4 bugtracker -e 'SHOW TABLES;' | wc -l
mariadb -u mantisbt -pq1w2e3r4 bugtracker -N -e 'SELECT username, enabled FROM mantis_user_table;'

实测输出:

33
administrator   1

(SHOW TABLES 输出含一行表头,33 行即 32 张业务表。)

再跑一次官方健康检查页 http://localhost:8132/mantisbt/admin/check/index.php(或 curl 抓取),实测发现的高价值警告节选:

MySQL Lifecycle and Release Support data availability
Release information for MySQL 10.6 series is not available, unable to perform the lifecycle check

webmaster_email configuration option has a valid email address specified
You need to specify a valid email address for the webmaster_email configuration option

from_email configuration option has a valid email address specified
You need to specify a valid email address for the from_email configuration option

max_file_size MantisBT option is less than or equal to the upload_max_filesize directive in php.ini

这些警告的处理方式(改 config_inc.php 邮箱三项、调 php.ini 上传上限)属于配置范畴,逐项闭环见《MantisBT 2.28.4 配置参数详解》。

4.8 首次登录并修改管理员密码

浏览器打开 http://localhost:8132/mantisbt/login_page.php,用默认账号 administrator / 密码 root 登录。登录表单除用户名密码外还携带隐藏字段 login_token(CSRF 防护),用 curl 模拟同一动作:

curl -s -c /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/login_page.php' -o /tmp/loginpage.html
TOKEN=$(grep -oE 'name="login_token" value="[^"]+"' /tmp/loginpage.html | sed 's/.*value="//;s/"//')
curl -s -b /tmp/mantis-ck.txt -c /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/login.php' \
  --data "return=my_view_page.php&login_token=$TOKEN&username=administrator&password=root" \
  -o /dev/null -w 'login %{http_code}\n'
curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/my_view_page.php' -o /dev/null -w 'my_view %{http_code}\n'

实测输出:

login 302
my_view 200

登录成功后立即改密:「个人资料(account_page.php)→ 更新用户」,需要填当前密码与新密码两次。等价 curl(先从账号页取 account_update_token):

curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/account_page.php' -o /tmp/account.html
TOKEN=$(grep -oE 'name="account_update_token" value="[^"]+"' /tmp/account.html | sed 's/.*value="//;s/"//')
curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/account_update.php' \
  --data "account_update_token=$TOKEN&email=administrator@mantis.local&realname=&password_current=root&password=q1w2e3r4&password_confirm=q1w2e3r4" \
  -o /dev/null -w 'update %{http_code}\n'

实测输出:

update 200

用新密码重新登录验证(实测 login 302、my_view 200,且页面出现 administrator 用户信息,改密生效)。首次改密时若邮箱填了 example.com 之类保留域名会触发 400(排障实录见第九节 Q2)。

4.9 创建项目与分类

以「管理 → 项目管理 → 创建新项目」新建项目 demo-app。表单核心字段:项目名称 name、描述 description、状态 status=10(开发中)、查看权限 view_state=10(公开)、继承全局分类 inherit_global=1,CSRF 字段为 manage_proj_create_token。curl 等价:

curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/manage_proj_create_page.php' -o /tmp/projcreate.html
T=$(grep -oE 'name="manage_proj_create_token" value="[^"]+"' /tmp/projcreate.html | sed 's/.*value="//;s/"//')
curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/manage_proj_create.php' \
  --data "manage_proj_create_token=$T&name=demo-app&description=Demo project for document testing&status=10&view_state=10&inherit_global=1" \
  -o /dev/null -w 'create %{http_code}\n'

实测输出:

create 302

在项目编辑页「分类」区添加默认分类 General(表单字段 project_id=1、name=General,CSRF 字段 manage_proj_cat_add_token,curl 实测 302 跳回项目编辑页)。用数据库验证两者落库:

mariadb -u mantisbt -pq1w2e3r4 bugtracker -N -e 'SELECT id,name,status FROM mantis_project_table; SELECT id,project_id,name FROM mantis_category_table;'

实测输出:

1       demo-app        10
1       0       General
2       1       General

(project_id=0 的 General 是全局默认分类,project_id=1 的是项目分类。)

4.10 报告第一个问题

「报告问题(bug_report_page.php?project_id=1)」表单核心字段:category_id=1(General)、summary(摘要)、description(描述)、severity=50(小错误)、priority=30(中)、view_state=10(公开)、CSRF 字段 bug_report_token。curl 等价(摘要「登录页验证码在低分辨率下重叠」):

curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/bug_report_page.php?project_id=1' -o /tmp/report.html
T=$(grep -oE 'name="bug_report_token" value="[^"]+"' /tmp/report.html | sed 's/.*value="//;s/"//')
curl -s -b /tmp/mantis-ck.txt 'http://localhost:8132/mantisbt/bug_report.php' \
  --data "bug_report_token=$T&m_id=&project_id=1&category_id=1&reproducibility=70&severity=50&priority=30&summary=%E7%99%BB%E5%BD%95%E9%A1%B5%E9%AA%8C%E8%AF%81%E7%A0%81%E5%9C%A8%E4%BD%8E%E5%88%86%E8%BE%A8%E7%8E%87%E4%B8%8B%E9%87%8D%E5%8F%A0&description=%E5%9C%A8%201280x720%20%E5%88%86%E8%BE%A8%E7%8E%87%E4%B8%8B%EF%BC%8C%E7%99%BB%E5%BD%95%E9%A1%B5%E9%AA%8C%E8%AF%81%E7%A0%81%E4%B8%8E%E8%BE%93%E5%85%A5%E6%A1%86%E9%87%8D%E5%8F%A0%EF%BC%8C%E6%97%A0%E6%B3%95%E8%BE%A8%E8%AE%A4%E3%80%82&steps_to_reproduce=%E6%89%93%E5%BC%80%20login_page.php&additional_info=&view_state=10&handler_id=0&report_stay=0&os=Ubuntu+22.04&os_build=&platform=PC&max_file_size=5000000" \
  -o /dev/null -D - | grep -E 'HTTP|Location'

实测输出:

HTTP/1.1 302 Found
Location: http://localhost:8132/mantisbt/view.php?id=1

访问 http://localhost:8132/mantisbt/view.php?id=1,实测页面标题与关键字段:

0000001: 登录页验证码在低分辨率下重叠 - MantisBT
编号 0000001   项目 demo-app   分类 General   查看权限 公开
报告员 administrator   优先级 中   严重性 小错误   状态 新建
摘要 0000001: 登录页验证码在低分辨率下重叠

数据库侧最终验证:

mariadb --default-character-set=utf8mb4 -u mantisbt -pq1w2e3r4 bugtracker -N -e 'SELECT id,project_id,category_id,severity,priority,status,summary FROM mantis_bug_table;'

实测输出:

1       1       1       50      30      10      登录页验证码在低分辨率下重叠

💡 说明:mariadb 客户端默认会话字符集可能不是 utf8mb4,查含中文的数据时显式加 --default-character-set=utf8mb4,否则中文会显示为一串问号。

至此「安装 → 登录 → 改密 → 建项目 → 提单」闭环全部走通。

五、方案 B:Nginx + PHP-FPM 部署(备用)

5.1 方案说明

与方案 A 共用同一操作系统与同一份发行包,仅把 Web 层从 Apache(mod_php) 换成 Nginx + PHP-FPM,并把站点根指到独立副本 /var/www/mantisbt-nginx、独立库 bugtracker_nginx,从而在单机上完整走一遍 0→1。适合已有 Nginx 栈或需要高并发静态资源处理的场景。

5.2 安装 Nginx 与 PHP-FPM

DEBIAN_FRONTEND=noninteractive apt-get install -y nginx php8.1-fpm

实测确认服务可启动并监听 8080(稍后配置):

service php8.1-fpm start
service nginx start

5.3 准备独立库与独立源码副本

建独立库并授权(与 4.4 同款姿势):

mariadb -e "CREATE DATABASE bugtracker_nginx CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; GRANT ALL PRIVILEGES ON bugtracker_nginx.* TO 'mantisbt'@'localhost'; FLUSH PRIVILEGES;"

复制一份全新源码并清掉配置(让向导重新生成),属主交给 www-data:

cp -a /var/www/html/mantisbt /var/www/mantisbt-nginx
rm -f /var/www/mantisbt-nginx/config/config_inc.php
chown -R www-data:www-data /var/www/mantisbt-nginx
ls -ld /var/www/mantisbt-nginx

实测输出:

drwx------ 17 www-data www-data 12288 Oct 21 07:26 /var/www/mantisbt-nginx

5.4 站点配置

写入 /etc/nginx/sites-available/mantisbt:

server {
    listen 8080;
    server_name _;
    root /var/www/mantisbt-nginx;
    index index.php;
    # REST API:把 /api/rest/* 路由到内置 Slim 入口(对应 Apache 的 api/rest/.htaccess 重写)
    location /api/rest {
        try_files $uri /api/rest/index.php$is_args$args;
    }
    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }
    # 禁止外网直接访问源码目录与实例配置(等价 Apache 的 .htaccess 保护)
    location ~ ^/(config|core|lang|library)/ {
        deny all;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    }
}

逐项说明:/api/rest 的 try_files 是 Nginx 版 REST 路由的关键(没有它 REST 全部 404,见第十节排障);deny all 把 config/(含数据库口令)与 core/、lang/、library/ 挡在外面;PHP 走 Unix socket 的 php8.1-fpm。

启用站点并验证配置:

ln -sf /etc/nginx/sites-available/mantisbt /etc/nginx/sites-enabled/mantisbt
rm -f /etc/nginx/sites-enabled/default
nginx -t
service nginx restart

实测输出:

nginx: configuration file /etc/nginx/nginx.conf test is successful

5.5 运行安装向导

浏览器访问 http://localhost:8080/admin/install.php,表单取值与 4.6 相同,仅 Database name 改为 bugtracker_nginx。curl 无人值守等价:

curl -s -m 120 -X POST 'http://127.0.0.1:8080/admin/install.php' \
  --data 'install=2&hostname=localhost&db_username=mantisbt&db_password=q1w2e3r4&database_name=bugtracker_nginx&admin_username=mantisbt&admin_password=q1w2e3r4&db_table_prefix=mantis&db_table_plugin_prefix=plugin&db_table_suffix=_table&go=Install%2FUpgrade+Database'

实测结果页统计:GOOD=237 BAD=0,且包含成功结论:

Installation Complete MantisBT was installed successfully. Continue to log in.

5.6 验证

curl -s -m 30 -I http://127.0.0.1:8080/login_page.php | head -3
curl -s -m 30 http://127.0.0.1:8080/login_page.php | grep -oE '<title>[^<]*'
curl -s -m 30 -o /dev/null -w 'core-protected %{http_code}\n' http://127.0.0.1:8080/core/php_api.php
curl -s -m 30 -o /dev/null -w 'config-protected %{http_code}\n' http://127.0.0.1:8080/config/config_inc.php
curl -s -m 30 -H 'Authorization: x' -o /dev/null -w 'rest-auth %{http_code}\n' http://127.0.0.1:8080/api/rest/users/me
mariadb -u mantisbt -pq1w2e3r4 bugtracker_nginx -N -e 'SELECT COUNT(*) FROM mantis_user_table;'

实测输出:

HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
<title>Login - MantisBT
core-protected 403
config-protected 403
rest-auth 401
1

解读:登录页 200 且 Server 头为 nginx;config/、core/ 被 403 拦截(保护生效);REST 端点 401(未带有效令牌,说明路由可达,令牌申请见《MantisBT 2.28.4 REST API 使用详解》);新库已有 1 个内置管理员账号。

六、方案对比与选择建议

维度方案 A:Apache + mod_php方案 B:Nginx + PHP-FPM
安装方式apt 系统源apt 系统源
是否需联网需(下载发行包)需(下载发行包)
REST 路由.htaccess 重写(需 AllowOverride All + CGIPassAuth)站点配置显式 try_files
目录保护发行包 .htaccess(需 AllowOverride All)站点配置 deny all
实测监听81328080
优点配置最少、官方默认路径、.htaccess 全套生效静态资源并发强、内存占用低、配置显式可控
缺点Ubuntu 默认 AllowOverride None,必须显式放开需手写 REST 与保护规则,漏写即 404/裸奔

选择建议:内网小团队、想「最少步骤跑起来」选方案 A;已有 Nginx 统一入口、或要和其它 Nginx 站点混部选方案 B。两方案共用一套 MariaDB 时注意库名要分开(本文用 bugtracker 与 bugtracker_nginx),避免向导互相覆盖。

七、配置说明

安装完成后与运维相关的配置落点:

  • 实例配置:/var/www/html/mantisbt/config/config_inc.php(安装向导生成),数据库连接、时区、加密盐、对外 URL 都在这里;后续所有参数调优也写在这个文件,改完即生效(PHP 每请求重新加载),无需重启服务。
  • 默认值参考:/var/www/html/mantisbt/config_defaults_inc.php,所有可调参数的官方默认值与注释都在此文件,排查「这个参数默认是多少」直接查它。
  • 字符串定制:/var/www/html/mantisbt/config/custom_strings_inc.php(自建),覆盖界面文案与本地化枚举标签,用法见配置参数详解篇。
  • php.ini 关键项:附件上限受 upload_max_filesize(Ubuntu 默认 2M)约束,需要更大附件时同步调整 php.ini 与 MantisBT 的 $g_max_file_size,两处必须一致(详见配置参数详解篇附件节)。
  • admin 目录:安装向导所在目录 admin/ 在生产环境应整体移除或加访问控制,否则每次进管理页都会看到健康检查的明文警告「admin目录应被移除,或已限制其访问权」。

八、升级、降级与多版本管理

8.1 升级流程

官方升级路径(Admin Guide「Upgrading」章)与本文实测工具一致,四步:

  1. 备份数据库与 config/config_inc.php(含 $g_crypto_master_salt,丢了 Cookie 与令牌全部失效):
mariadb-dump -u mantisbt -pq1w2e3r4 bugtracker > bugtracker-$(date +%F).sql
cp -a /var/www/html/mantisbt/config/config_inc.php /root/config_inc.php.bak
  1. 下载新版 tarball,解压后替换程序文件(保留 config/ 目录)。
  2. 访问 admin/install.php(或 CLI 方式)执行 schema 升级。官方提供静默升级脚本:
cd /var/www/html/mantisbt/admin && php upgrade_unattended.php

本文在已装好的 2.28.4 上实测该脚本(schema 已是最新时的回显,可作为升级后「无待执行升级」的验证基准):

Post 1.0 schema changes
Connecting to database... OK
0 schema upgrades executed.
Done.
  1. 浏览器回归登录、提单、查看历史问题三条主链路。

8.2 降级说明

官方 Admin Guide 只提供升级路径,未提供降级支持:schema 升级是单向 DDL,跨大版本降级需用 8.1 步的备份库还原 + 旧版程序文件回滚,且不接受降级期间的增量数据。生产操作前务必以备份为底线。

8.3 多版本并存

同一服务器可并存多套实例:每套独立源码目录(如本文的 /var/www/html/mantisbt 与 /var/www/mantisbt-nginx)+ 独立数据库(bugtracker 与 bugtracker_nginx)+ 独立站点端口(8132 与 8080)。注意 $g_crypto_master_salt 每套独立,禁止复制;表前缀(db_table_prefix)如共用一个库则必须不同。

九、常见问题(FAQ)

Q1:curl 模拟登录返回 403,页面报 APPLICATION ERROR #2800 Invalid form security token? MantisBT 从 2.x 起登录表单也带 CSRF 令牌。必须先 GET login_page.php(同一 Cookie 会话)提取隐藏字段 login_token,再把它随 POST 提交;本节 4.8 的两段式 curl 即标准解法。

Q2:修改资料报 APPLICATION ERROR #1201 It is not allowed to use disposable e-mail addresses? 2.28 起内置一次性邮箱域名拦截,example.com 等保留域名会被拒。实测换成自定域名(如 administrator@mantis.local)后返回 200。另注意:邮箱变更会触发「Verify Email Address」验证邮件,旧地址在确认前保持生效,验证邮件会同时抄送旧地址。

Q3:创建用户报 APPLICATION ERROR #803 密码与确认信的内容不匹配? 管理后台「创建用户」表单在默认配置下根本不出现密码框(新用户靠邮件里的链接自设密码),如果 curl 多传了 password 而没有成对的确认字段就会报 803。按表单实际字段提交(用户名/邮箱/访问级别)即可。

Q4:创建用户报 APPLICATION ERROR #813 电子邮件已被使用? 邮箱在用户表中必须唯一。实测中 administrator 先占用了 root@localhost,再创建 root@localhost 的 dev1 即报 813;换未占用邮箱或先释放原账号邮箱。

Q5:安装向导结果页出现 POSSIBLE PROBLEM Can't retrieve web page at ...? 向导会回访 $g_path 自检。经反向代理、端口映射或防火墙部署时该回访可能失败,属可忽略告警;关键是安装后核对并修正 config/config_inc.php 的 $g_path(本文实测值为 http://localhost:8132/mantisbt/),否则页面里的绝对链接与 REST 回调都会指错。

Q6:健康检查与页面顶部提示「admin 目录应被移除,或已限制其访问权」? 这是对 admin/ 安装维护目录的访问面警告。生产环境二选一:删除 admin/ 目录(升级时再放回),或在 Web 服务器层加 IP 白名单/Basic 认证。

Q7:附件上传页显示「最大文件大小: 2,048 KiB」,传大文件被拒? 该上限取 min(php.ini 的 upload_max_filesize, $g_max_file_size),Ubuntu 的 PHP 默认 upload_max_filesize=2M。要放大附件,同时修改 /etc/php/8.1/apache2/php.ini(方案 B 为 /etc/php/8.1/fpm/php.ini)的 upload_max_filesize 与 post_max_size,以及 config_inc.php 的 $g_max_file_size,改完方案 B 需重启 php8.1-fpm。

十、卸载与清理

完整卸载 MantisBT(以方案 A 为例,方案 B 追加 /var/www/mantisbt-nginx 与 Nginx 站点文件):

# 1. 停服务(如需整机回收再一并停 Apache/MariaDB)
service apache2 stop

# 2. 删除程序与实例配置
rm -rf /var/www/html/mantisbt

# 3. 删除数据库与账号
mariadb -e "DROP DATABASE IF EXISTS bugtracker; DROP USER IF EXISTS 'mantisbt'@'localhost'; FLUSH PRIVILEGES;"

# 4. 确认端口释放
ss -ltn | grep :8132 || echo 8132 已释放

实测输出:

8132 已释放

只卸程序不卸库:跳过第 3 步,保留的 SQL 备份与 bugtracker 库可供重装后恢复。

十一、参考链接