本文示範在 Linux 上從原始碼編譯安裝 Apache 1.3.6、PHP 3.0.5 與 PostgreSQL 6.4,構建 Web 資料庫應用平台。
官網 postgresql.org 下載最新版(本文以 6.4 為例)。
/usr/local/pgsql,需預留 50MB 空間postgres:adduser postgresoptions SYSVSHM SYSVSEM SYSVMSGsu postgres tar -xzvf postgresql-v6.4.tar.gz cd postgresql-v6.4/src ./configure --with-mb=EUC_CN # 指定預設編碼(支援 BIG5、EUC_JP 等) gmake all gmake install gmake install-man
在 ~/.bashrc (bash) 或 ~/.cshrc (tcsh) 設定:
export PATH="$PATH":/usr/local/pgsql/bin export POSTGRES_HOME=/usr/local/pgsql export PGLIB=$POSTGRES_HOME/lib export PGDATA=$POSTGRES_HOME/data export MANPATH="$MANPATH":$POSTGRES_HOME/man export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"
初始化資料庫叢集:initdb(可用 --pgencoding 指定編碼)。啟動:postmaster -S。執行測試:cd test/regression && gmake all runtest。
Linux:在 /etc/rc.d/rc.local 加入啟動腳本。FreeBSD:建立 /usr/local/etc/rc.d/pgsql.sh。
createuser nobody # 為 Apache 用戶建立 DB 帳號 createdb dbname # 建立資料庫 destroydb dbname # 刪除資料庫 pgsql dbname # 互動式 SQL 工具
host all 127.0.0.1 255.255.255.255 password passwd 允許本機密碼驗證。GRANT SELECT,INSERT ON table TO user / REVOKE。Apache: apache.org、PHP: php.net。
# 解壓並編譯 Apache cd /usr/local/src tar -xzvf /tmp/apache_1.3.6.tar.gz cd apache_1.3.6 ./configure # 解壓 PHP cd /usr/local/src tar -xzvf /tmp/php3-3.0.5.tar.gz # PHP 需指定 --with-apache=../apache_1.3.6 --with-pgsql=/usr/local/pgsql # 然後重新編譯 Apache 以內嵌 PHP 模組
關鍵步驟:PHP 設定時需指定 Apache 原始碼路徑與 PostgreSQL 安裝路徑,再回到 Apache 目錄執行 ./configure --activate-module=src/modules/php3/libphp3.a 並 make、make install。
httpd.conf 載入 PHP 模組、設定 AddType application/x-httpd-php3 .php3php3.ini 設定資料庫連線參數phpinfo() 與資料庫連線程式