MantisBT是一款界面简洁但功能强大的Bug追踪系统,也可以做轻量级的项目管理。本文介绍MantisBT在LNMP环境下的安装配置。
MantisBT的系统占用极低,单核1GB内存的云服务器就可以满足需求。操作系统我选择了Ubuntu 20.04 x64 Server版,其它Linux系统也大致相同。
安装完Ubuntu系统后,更新系统并安装必须的软件:
$ sudo apt update $ sudo apt upgrade $ sudo apt autoremove $ sudo apt install nginx mysql-server php-fpm php-mbstring php-mysql postfix |
接下来我们解压MantisBT的安装包:
$ sudo mkdir /opt/mantisbt $ sudo chown `whoami`:`whoami` /opt/mantisbt $ tar -xvf mantisbt-2.24.3.tar.xz -C /opt/mantisbt/ $ chmod 775 /opt/mantisbt/mantisbt-2.24.3 |
因为现在HTTPS的访问方式已经是主流,我们可以让HTTP的访问请求都转到HTTPS的URL。创建/opt/mantisbt/mantisbt_http/index.html文件:
1 2 3 | <html> <meta http-equiv="refresh" content="0;url=https://example.com/"> </html> |
然后我们将适用于Nginx的证书存放到固定的目录:
$ mkdir /opt/mantisbt/ticket_cert $ cp ~/example.com.pem /opt/mantisbt/ticket_cert/ $ cp ~/example.com.key /opt/mantisbt/ticket_cert/ |
创建HTTPS的Nginx文件/etc/nginx/sites-enabled/ticket_https.conf:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | server { listen 443 ssl; server_name example.com; ssl_certificate /opt/mantisbt/ticket_cert/example.com.pem; ssl_certificate_key /opt/mantisbt/ticket_cert/example.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; root /opt/mantisbt/mantisbt-2.24.3; index index.php; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } client_max_body_size 16m; } |
创建HTTP的Nginx文件/etc/nginx/sites-enabled/ticket.conf:
1 2 3 4 5 6 7 8 9 10 | server { listen 80; server_name example.com; root /opt/mantisbt/mantisbt_http; index index.html; location / { try_files $uri $uri/ =404; } client_max_body_size 16m; } |
我们将运行Nginx的用户改为当前用户,这样文件的权限上更单纯。修改/etc/nginx/nginx.conf:
1 2 3 4 5 | -user www-data; +user ct ct; worker_processes auto; pid /run/nginx.pid; include /etc/nginx/modules-enabled/*.conf; |
同时我们变更php-fpm的监听权限,修改/etc/php/7.4/fpm/pool.d/www.conf:
1 2 3 4 5 6 7 8 9 10 | ; BSD-derived systems allow connections regardless of permissions. ; Default Values: user and group are set as the running user ; mode is set to 0660 listen.owner = www-data listen.group = www-data -;listen.mode = 0660 +listen.mode = 0666 ; When POSIX Access Control Lists are supported you can set them using ; these options, value is a comma separated list of user/group names. ; When set, listen.owner and listen.group are ignored |
重启Nginx和php-fpm:
$ sudo service nginx restart $ sudo service php7.4-fpm restart |
MantisBT需要使用MySQL存储数据。较新的Ubuntu上,要登录MySQL需要首先获取管理员用户名和密码:
1 2 3 4 5 6 7 8 9 10 11 12 | $ sudo cat /etc/mysql/debian.cnf # Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = WPAhowIN3uvVHtVI socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = WPAhowIN3uvVHtVI socket = /var/run/mysqld/mysqld.sock |
使用这组用户名和密码连接MySQL并新增MantisBT的数据库和用户:
$ mysql -u debian-sys-maint -p mysql> CREATE DATABASE ticket CHARACTER SET utf8 COLLATE utf8_bin; mysql> CREATE USER 'ticketuser'@'127.0.0.1' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON ticket.* TO 'ticketuser'@'127.0.0.1'; mysql> SHOW GRANTS FOR 'ticketuser'@'127.0.0.1'; mysql> quit; |
此时可以通过浏览器打开http://ip,配置MySQL后再遵循指引安装设置即可:
1 2 3 4 5 | Type of Database: MySQL Improved Hostname: 127.0.0.1 Username: ticketuser Password: password Database name: ticket |
安装设置完成后,在/opt/mantisbt/mantisbt-2.24.3/config/config_inc.php文件中增加各项配置,特别是邮件服务器的配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <?php $g_crypto_master_salt = '9ZX1ONWx6IWuM1iyAGLMZx9zVGRnFpM='; $g_hostname = '127.0.0.1'; $g_db_type = 'mysqli'; $g_database_name = 'ticket'; $g_db_username = 'ticketuser'; $g_db_password = 'password'; $g_window_title = 'Ticket'; $g_allow_signup = OFF; $g_rss_enabled = OFF; $g_show_realname = ON; $g_default_timezone = 'Asia/Shanghai'; $g_default_language = 'auto'; $g_timeline_view_threshold = ADMINISTRATOR; $g_email_receive_own = OFF; $g_administrator_email = 'ticket@example.com'; $g_webmaster_email = 'ticket@example.com'; $g_from_email = 'ticket@example.com'; $g_from_name = 'Ticket'; $g_return_path_email = 'ticket@example.com'; $g_phpMailer_method = PHPMAILER_METHOD_SMTP; $g_smtp_host = 'smtp.exmail.qq.com'; $g_smtp_username = 'ticket@example.com'; $g_smtp_password = 'password'; $g_smtp_connection_mode = 'tls'; $g_smtp_port = 587; $g_email_send_using_cronjob = ON; $g_bug_link_tag = '#'; $g_bugnote_link_tag = '~'; $g_html_valid_tags = 'p, li, ul, ol, br, pre, code, i, b, u, em, strong'; #$g_logo_image = 'images/mantis_logo.png'; #$g_status_colors['new'] = '#C25428'; #$g_status_colors['feedback'] = '#479E98'; #$g_status_colors['acknowledged'] = '#89972C'; #$g_status_colors['confirmed'] = '#B28A2B'; #$g_status_colors['assigned'] = '#398BCD'; #$g_status_colors['resolved'] = '#EEE8D7'; #$g_status_colors['closed'] = '#95A1A1'; #$g_css_include_file = "css/custom.css"; ?> |
在css/custom.css中我们可以设置字体或其它CSS样式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | pre { /* border-left: 5px solid #ccc; */ margin-left: 2em; padding-left: 5px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 90%; } code { color: #666; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 90%; } input { font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 90%; } textarea.form-control { font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 90%; } |