詳細記錄在 Linux 上從源碼編譯安裝 Apache、MySQL、PHP5,並部署 WordPress、phpWind、phpBB3、Discuz 等主流論壇/博客系統的完整流程。
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
(文中提供完整 SysV init 腳本,支援 start/stop/restart/reload/status)
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 密碼、建立啟動腳本(略,參考官方文檔)。
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
編輯 /usr/local/apache/conf/httpd.conf:
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps DirectoryIndex index.html index.php
建立四個基於域名的虛擬主機:
每個虛擬主機配置 DocumentRoot、Directory 權限、ErrorLog/CustomLog,解壓對應程式包至網站目錄,配置資料庫連線,瀏覽器完成安裝向導。
libxml2、libjpeg、libpng、freetype 等開發包,缺失會導致 GD 模組構建失敗。scripts/mysql_install_db 初始化系統表。httpd: Could not reliably determine the server's fully qualified domain name,設定 ServerName 即可。chown -R apache:apache)。pdo_mysql、mbstring、gd 擴展。源碼編譯部署雖步驟多,但能精確控制版本、模組與優化參數,是高可用生產環境的首選方式。