FreeBSD
cd /usr/ports/databases/mysql4-server
因為我安裝系統時把資料庫獨立分了一個分割區,所以要改一下 MySQL 預設的存放目錄。編輯 Makefile:
ee Makefile
把 DB_DIR?= 改成你的資料庫目錄,並在 CONFIGURE_TARGET 那行之前的空行加上兩行最佳化選項:
BUILD_OPTIMIZED=yes
BUILD_STATIC= yes
存檔退出後編譯安裝:
make
make install clean
裝好後編輯啟動腳本:
ee /usr/local/bin/mysqld_safe
往下找到第 314 行(4.0.20 版),這行很長,以 $NOHUP_NICENESS 開頭、>> $err_log 2>&1 結尾,並被嵌在一個 if 陳述裡。在該行末尾的 " >> $err_log 2>&1" 之前加上 " -O max_connections=1000"(前後各留一個空格)。再往下找到第 316 行,同樣很長,以 eval "$NOHUP_NICENESS 開頭,做同樣的修改。
存檔後重啟,這時的 mysql40 就是 1000 條並發連線的資料庫了。可以這樣驗證:
cd /usr/local/bin
mysqladmin -uroot -p variables
會列出一長串變數,按 Scroll Lock 向上捲動,看到 | max_connections | 1000 | 就代表修改成功。
修改 root 密碼:
mysqladmin -u root password '你要的密碼'
先裝 openssl:
cd /usr/ports/security/openssl
make install clean
順手升級 expat2:
cd /usr/ports/textproc/expat2
make deinstall
make install clean
安裝 apache2:
cd /usr/ports/www/apache2
make install clean
安裝 fastcgi 模組:
cd /usr/ports/www/mod_fastcgi
make WITH_APACHE2=yes install clean
cd /usr/ports/www/mod_php4
make install clean
裝好後 /usr/local/etc/apache2 底下已經有幾個 httpd 設定檔範本,複製一份作為正式設定:
cp /usr/local/etc/apache2/httpd-dist.conf /usr/local/etc/apache2/httpd.conf
編輯它:
ee /usr/local/etc/apache2/httpd.conf
在 AddType application/x-gzip .gz .tgz 之後加上 PHP 支援:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
把 DirectoryIndex 那行改為允許 index.php 作為預設首頁:
DirectoryIndex index.html index.htm index.php index.html.var
把預設字元集設為簡體中文:找到 AddDefaultCharset 改成 AddDefaultCharset GB2312。
訪問量大的網站,Apache 預設的 150 連線遠遠不夠,以下各項改為:
StartServers 10
MinSpareServers 10
MaxSpareServers 15
ServerLimit 2000
MaxClients 1500
MaxRequestsPerChild 10000
要讓 Apache 開機自啟,編輯 /etc/rc.conf 加入:
apache2_enable="YES"
apache2ssl_enable="YES"
接著試著啟動:
/usr/local/etc/rc.d/apache2.sh start
如果提示 ssl.conf 某行有錯、找不到 server.crt,那麼恭喜你跟我一樣中獎了。不知這是否為 apache2 port 的 bug,總之這樣裝出來的 apache + mod_ssl 沒有伺服器憑證,啟動會失敗,我們得自己簽一張。
先下載憑證產生程式 https://www.openssl.org/contrib/ssl.ca-0.1.tar.gz,然後:
tar zxvf ssl.ca-0.1.tar.gz
cd ssl.ca-0.1
./new-root-ca.sh
./new-server-cert.sh server
./sign-server-cert.sh server
後三個指令執行時會問一連串問題:密碼、省份、城市、單位等等,看著辦吧。友情提示:執行 ./new-server-cert.sh server 時,commonName 最好與你的 ServerName 一致,否則 Apache 啟動時會寫入錯誤日誌。
接著到 /usr/local/etc/apache2 建兩個目錄存放 crt 與 key:
mkdir ssl_crt
mkdir ssl_key
把產生的四個檔案放進去並調整權限:
cp ca.crt /usr/local/etc/apache2/ssl_crt
cp ca.key /usr/local/etc/apache2/ssl_key
cp server.crt /usr/local/etc/apache2/ssl_crt
cp server.key /usr/local/etc/apache2/ssl_key
cd /usr/local/etc/apache2/ssl_key
chmod 444 server.key
cd /usr/local/etc/apache2/ssl_crt
chmod 444 server.crt
搞定,現在啟動 apache2 應該就沒問題了。