Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

從零打造 Linux + Apache + PHP + MySQL + Zend Optimizer + phpMyAdmin 環境

論壇裡大量提問都關於網站空間搭建,這篇就以能順暢跑 Discuz! 為目標,走一遍完整流程。原則只有一個:用不到的東西就不裝、不編、不配,讓系統保持乾淨輕快。

一、準備軟體

以下版本為當時的推薦版本:

Apache 2.0.55、PHP 4.4.1、MySQL 4.0.26、Zend Optimizer 2.6.0、phpMyAdmin 2.7.0-pl1,皆可從各自的官方下載頁取得。

二、先確認 GD 相關依賴

Discuz! 4.0 的水印功能需要 GD 函式庫,先檢查:

# rpm -qa | grep zlib
# rpm -qa | grep libpng
# rpm -qa | grep freetype
# rpm -qa | grep jpeg
# rpm -qa | grep gd

缺哪些就手動補:

(1) zlib
# tar zxvf zlib-1.2.2.tar.gz
# cd zlib-1.2.2 && ./configure && make && make install

(2) libpng(注意 makefile 不是用 configure 產生,而是從 scripts 複製)
# tar zxvf libpng-1.2.7.tar.tar
# cd libpng-1.2.7/scripts && mv makefile.linux ../makefile
# cd .. && make && make install

(3) freetype
# tar zxvf freetype-2.1.9.tar.gz
# cd freetype-2.1.9 && ./configure && make && make install

(4) jpeg(configure 務必帶 --enable-shared,否則不會產生共享庫)
# tar zxvf jpegsrc.v6b.tar.gz
# cd jpeg-6b && ./configure --enable-shared && make && make test && make install

(5) GD
# tar zxvf gd-2.0.33.tar.gz
# cd gd-2.0.33 && ./configure --with-png --with-freetype --with-jpeg && make install

三、安裝 MySQL

先檢查光碟是否已自帶 MySQL RPM:

# rpm -qa | grep mysql

若有,先移除(遇到相依性問題可用 --nodeps 或 --force 強制移除):

# rpm -e MySQL-xxxxxx

再安裝新版本並啟動:

# rpm -ivh MySQL-client-4.0.26-0.i386.rpm
# rpm -ivh MySQL-server-4.0.26-0.i386.rpm
# /etc/rc.d/init.d/mysql start
# mysqladmin -u root password new_password_for_root

四、編譯安裝 Apache

只啟用動態模組載入以節省記憶體,其他模組日後再手動掛上:

# tar xzvf httpd-2.0.55.tar.gz
# cd httpd-2.0.55
# ./configure --prefix=/usr/local/apache --enable-so
# make && make install

編輯 /usr/local/apache/conf/httpd.conf,只需改這幾處:

ServerAdmin 改為管理員信箱;ServerName 改為伺服器網域(如 www.yourdomain.com:80);DocumentRoot 改為網站根目錄(如 "/var/www")。

五、編譯安裝 PHP 並與 Apache 整合

# tar xzvf php-4.4.1.tar.gz
# cd php-4.4.1
# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs \
  --with-mysql --with-config-file-path=/usr/local/php/etc \
  --with-gd --enable-gd-native-ttf --enable-gd-jis-conv \
  --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
  --enable-xml --enable-mbstring
# make && make install
# cp php.ini-recommend /usr/local/php/etc/php.ini

回到 httpd.conf:在 DirectoryIndex 後面加上 index.php;在 AddType application/x-gzip .gz .tgz 下方新增一行:

AddType application/x-httpd-php .php

六、安裝 Zend Optimizer

# tar xzvf Zend*.gz
# rm -f Zend*.gz
# cd Zend*
# ./install.sh

安裝精靈很友善,唯一要留意的是 php.ini 路徑必須填對:/usr/local/php/etc。完成後它會自動重啟 Apache。

七、安裝設定 phpMyAdmin

# tar xzvf phpMyAdmin-2.7.0-pl1.tar.gz
# mv phpMyAdmin-2.7.0-pl1 /var/www/phpMyAdmin
# cd /var/www/phpMyAdmin
# vi config.inc.php

重點設定:

$cfg['PmaAbsoluteUri'] 填 phpMyAdmin 的絕對 URL;$cfg['blowfish_secret'] 設為 cookie 加密;$cfg['Servers'][$i]['connect_type'] 設為 socket;['compress'] 設 TRUE 啟用壓縮加速(若頁面異常改回 FALSE);['auth_type'] 設為 cookie 驗證。

結語

環境完成後即可上傳 Discuz! 開始安裝論壇。至於效能調優因人而異,務必依自己的硬體配置與實際負載找資料調整,切勿生搬硬套,否則往往適得其反。

Copyright © Linux教程網 All Rights Reserved