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

Linux 源碼編譯安裝 Apache + MySQL + PHP5 及主流論壇部署全記錄

編輯:Linux 教學

詳細記錄在 Linux 上從源碼編譯安裝 Apache、MySQL、PHP5,並部署 WordPress、phpWind、phpBB3、Discuz 等主流論壇/博客系統的完整流程。

軟體包準備

  • httpd-2.2.17.tar.bz2
  • mysql-5.1.50-linux-i686-glibc23.tar.gz(二進制包)
  • php-5.3.5.tar.bz2
  • wordpress-3.0.4-zh_CN.zip
  • phpwind_GBK_8.3.zip、phpBB3、Discuz 等

一、Apache 編譯安裝

tar -jxf httpd-2.2.17.tar.bz2
cd httpd-2.2.17
./configure --prefix=/usr/local/apache \
  --sysconfdir=/etc/httpd \
  --enable-so \
  --enable-modules=most \
  --enable-mod-shared=most \
  --enable-proxy \
  --enable-rewrite
make && make install

關鍵參數說明:
--enable-so:啟用 DSO 動態模組支援
--enable-mod-shared=most:大多數模組編譯為共享模組
--enable-rewrite:URL 重寫模組

環境變數與庫文件鏈接

echo "PATH=\$PATH:/usr/local/apache/bin" >> /etc/profile
ln -sv /usr/local/apache/include /usr/include/httpd
echo "/usr/local/apache/lib" > /etc/ld.so.conf.d/httpd.conf
ldconfig

建立啟動腳本 /etc/rc.d/init.d/httpd

(文中提供完整 SysV init 腳本,支援 start/stop/restart/reload/status)

二、MySQL 安裝(二進制包)

tar -xf mysql-5.1.50-linux-i686-glibc23.tar.gz -C /usr/local/
ln -s mysql-5.1.50 /usr/local/mysql
cd /usr/local/mysql

鏈接頭文件、庫文件、手冊頁

ln -sv /usr/local/mysql/include /usr/include/mysql
echo "PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile
echo "MANPATH /usr/local/mysql/man" >> /etc/man.conf

初始化數據庫、設定 root 密碼、建立啟動腳本(略,參考官方文檔)。

三、PHP5 編譯安裝

tar -xf php-5.3.5.tar.bz2
cd php-5.3.5
./configure --prefix=/usr/local/php5 \
  --sysconfdir=/etc/php5 \
  --with-mysql=/usr/local/mysql \
  --with-apxs2=/usr/local/apache/bin/apxs
make && make install

四、Apache 整合 PHP

編輯 /usr/local/apache/conf/httpd.conf:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php

五、虛擬主機部署論壇/博客

建立四個基於域名的虛擬主機:

  • www.phpwind.com
  • www.wordpress.com
  • www.phpbb3.com
  • www.discuz.com

每個虛擬主機配置 DocumentRoot、Directory 權限、ErrorLog/CustomLog,解壓對應程式包至網站目錄,配置資料庫連線,瀏覽器完成安裝向導。

關鍵避坑提醒

  • PHP 編譯需 libxml2、libjpeg、libpng、freetype 等開發包,缺失會導致 GD 模組構建失敗。
  • MySQL 二進制包需手動執行 scripts/mysql_install_db 初始化系統表。
  • Apache 啟動報錯 httpd: Could not reliably determine the server's fully qualified domain name,設定 ServerName 即可。
  • 論壇安裝目錄需 Web 進程用戶寫入權限(chown -R apache:apache)。
  • Discuz X 系列需 PHP 5.3+、MySQL 5.0+、開啟 pdo_mysql、mbstring、gd 擴展。

源碼編譯部署雖步驟多,但能精確控制版本、模組與優化參數,是高可用生產環境的首選方式。

Copyright © Windows教程網 All Rights Reserved