Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

CentOS 7 編譯安裝 Nginx + MySQL + PHP 部署 BugFree 缺陷管理系統全紀錄

編輯:關於伺服器

BugFree 是淘寶開源的缺陷管理系統,基於 PHP + MySQL。本文記錄在已安裝 Nginx + MySQL 的 CentOS 7 環境下,從源碼編譯安裝 PHP (含 pdo_mysql)、配置 Nginx 虛擬主機、解決 URL 重寫、部署 BugFree 3.0 的完整實戰過程與避坑指南。

環境基線

  • OS: CentOS 7.9 (Minimal)
  • Nginx: 1.24.0 (已編譯安裝至 /usr/local/nginx)
  • MySQL: 5.7.42 (已編譯安裝至 /usr/local/mysql)
  • 目標: 部署 BugFree 3.0.3 至 /data/www/bugfree

PHP 編譯安裝 (關鍵: --with-pdo-mysql)

# 1. 安裝依賴 (含 MySQL 開發庫)
yum install -y gcc gcc-c++ libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel \
    freetype-devel libmcrypt-devel mhash-devel libxslt-devel bzip2-devel \
    mysql-devel  # 關鍵: 提供 mysql.h, 解決 "Cannot find MySQL header files"

# 2. 下載 PHP 5.2.13 (BugFree 3.0 需求) 及 FPM 補丁
wget https://museum.php.net/php5/php-5.2.13.tar.gz
wget https://php-fpm.org/downloads/php-5.2.13-fpm-0.5.13.diff.gz

# 3. 應用補丁並編譯
tar zxvf php-5.2.13.tar.gz
gzip -cd php-5.2.13-fpm-0.5.13.diff.gz | patch -d php-5.2.13 -p1
cd php-5.2.13

./configure \
    --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/php/etc \
    --enable-fpm \
    --with-mysql=/usr/local/mysql \
    --with-pdo-mysql=/usr/local/mysql \  # 關鍵: 支持 PDO MySQL
    --with-mysqli=/usr/local/mysql/bin/mysql_config \
    --with-iconv-dir=/usr/local \
    --with-freetype-dir --with-jpeg-dir --with-png-dir \
    --with-zlib --with-libxml-dir --enable-xml \
    --enable-mbstring --enable-sockets --enable-bcmath \
    --with-mcrypt --with-mhash \
    --disable-rpath --enable-inline-optimization
make && make install

# 4. 配置 php-fpm
cp php.ini-dist /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# 編輯 php-fpm.conf 設置 user/group=www, listen=/tmp/php-cgi.sock, pm.max_children=50 等

Nginx 虛擬主機配置 (支援 BugFree URL 重寫)

server {
    listen 80;
    server_name bugfree.example.com;
    root /data/www/bugfree;
    index index.php index.html;

    access_log /var/log/nginx/bugfree_access.log;
    error_log /var/log/nginx/bugfree_error.log;

    # 1. 靜態資源
    location ^~ /static/ { expires 30d; access_log off; try_files $uri =404; }
    location ^~ /uploads/ { expires 7d; location ~ \.php$ { deny all; } }

    # 2. BugFree URL 重寫 (關鍵: 入口文件 index.php)
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # 3. PHP 處理
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/tmp/php-cgi.sock;  # 或 127.0.0.1:9000
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param PATH_INFO $fastcgi_path_info;  # 支持 PATH_INFO 模式
    }

    # 4. 安全: 隱藏文件、版本控制目錄
    location ~ /\.(git|svn|htaccess) { deny all; }
}

BugFree 部署與安裝

  1. 下載解壓:
    wget https://github.com/bugfree/bugfree/archive/refs/tags/3.0.3.tar.gz
    tar zxvf 3.0.3.tar.gz && mv bugfree-3.0.3 /data/www/bugfree
  2. 權限設置:
    chown -R www:www /data/www/bugfree
    chmod -R 755 /data/www/bugfree
    chmod -R 777 /data/www/bugfree/runtime /data/www/bugfree/uploads
  3. 創建數據庫:
    mysql -u root -p -e "CREATE DATABASE bugfree DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"
  4. Web 安裝向導:
    瀏覽器訪問 https://bugfree.example.com/install.php,按提示填寫數據庫信息、管理員帳號完成安裝。

核心避坑指南

問題現象根因解決方案
PHP 編譯報錯 "Cannot find MySQL header files"缺少 mysql-devel 包yum install mysql-devel (或指定 --with-mysql=/usr/local/mysql)
安裝向導「下一步」無響應 / 404Nginx 未正確配置 PATH_INFO / URL 重寫確保 location / { try_files ... /index.php?$query_string; } 且 PHP location 傳遞 PATH_INFO
登錄後「site/login」訪問異常BugFree urlManager 配置與 Nginx 重寫衝突修改 protected/config/main.php 關閉 urlManager 的 showScriptName 或調整規則
上傳附件失敗uploads 目錄權限不足 / PHP upload_max_filesize 限制chmod 777 uploads; php.ini 設置 upload_max_filesize=20M post_max_size=30M
郵件通知不發送PHP mail() 未配置 / 服務器無 MTA配置 SMTP (php.ini sendmail_path) 或使用 PHPMailer/SwiftMailer 類庫

驗證清單

  • [ ] 瀏覽器訪問首頁正常顯示登錄頁
  • [ ] 管理員帳號登錄成功,進入儀表板
  • [ ] 創建項目、模塊、缺陷、測試用例全流程無報錯
  • [ ] 附件上傳/下載正常
  • [ ] 郵件通知觸發正常 (可選)
  • [ ] Nginx/PHP-FPM/MySQL 服務開機自啟 (systemctl enable)

通過標準化編譯安裝、精確的 Nginx 重寫規則、權限與配置微調,可在現有 LNMP 基礎上平滑部署 BugFree 等傳統 PHP 應用。

Copyright © Windows教程網 All Rights Reserved