下載來源
MySQL 安裝
cp mysql-standard-5.0.1-alpha-snapshot-pc-linux-i686.tar.gz /usr/local/
tar -zxvf mysql-standard-5.0.1-alpha-snapshot-pc-linux-i686.tar.gz
cd mysql-standard-5.0.1-alpha-pc-linux-i686/
emacs INSTALL-BINARY # 閱讀安裝說明
groupadd mysql
useradd -g mysql mysql
cd /usr/local
ln -s mysql-standard-5.0.1-alpha-pc-linux-i686/ mysql
./scripts/mysql_install_db --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
./bin/mysqld_safe --user=mysql &
# 出現 "Starting mysqld daemon with databases from /usr/local/mysql/data" 即成功
ps -aux | grep mysql # 驗證進程
Apache 安裝
tar -zxvf httpd-2.0.52.tar.gz
cd httpd-2.0.52
emacs INSTALL
./configure --enable-so
make && make install
cd /usr/local/apache2/bin
./apachectl start
# 瀏覽器訪問 127.0.0.1 或主機名,看到羽毛圖示即成功
# 修正 ServerName 警告
cd /usr/local/apache2/conf
cp httpd.conf httpd.conf.bak
emacs httpd.conf
# 將 #ServerName www.example.com:80 改為
ServerName 127.0.0.1
./apachectl restart
PHP 安裝
tar -zxvf php-5.0.2.tar.gz
cd php-5.0.2
emacs INSTALL
./configure --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql
# 出現 License 確認提示輸入 yes 繼續
make && make install
cp php.ini-dist /usr/local/lib/php.ini
PHP 與 Apache 整合
emacs /usr/local/apache2/conf/httpd.conf
# DirectoryIndex 加入 index.php
DirectoryIndex index.html index.php index.htm index.html.var
# AddType 區段後加入
AddType application/x-httpd-php .php
/usr/local/apache2/bin/apachectl restart
測試 PHP
emacs /usr/local/apache2/htdocs/index.php
# 內容:
# 瀏覽器訪問 https://127.0.0.1/index.php 看到 PHP 資訊頁即成功
關鍵經驗總結
- 強烈建議原始碼安裝:知曉每一步、每個檔案位置,除錯不盲目
- 依賴關係順序:先 Apache、後 PHP(需 apxs)、最後 MySQL,或依 configure 參數調整
- 缺少依賴即裝:如
libxml2 版本過舊,需手動編譯升級(libxml2-2.6.10.tar.gz)
- 出錯先看錯誤訊息:
config.log、make 輸出、系統日誌,對症下藥