在無套件管理器環境下,從原始碼編譯安裝 PHP、PCRE、Lighttpd 並串聯 FastCGI 的完整操作紀錄。
tar zxf php-5.3.2.tar.gz -C /usr/src
cd /usr/src/php-5.3.2
./configure --prefix=/usr/local/php5 --enable-force-cgi-redirect --enable-fastcgi
make && make install
cp php.ini-dist /etc/php.ini
cd /usr/local/php5/bin
./php-cgi -b 127.0.0.1:9999 # 啟動 FastCGI 進程監聽 9999 埠
tar -zxf pcre-7.8.tar.gz && cd pcre-7.8
./configure && make && make install
tar -jxf lighttpd-1.4.28.tar.bz2 && cd lighttpd-1.4.28
./configure && make && make install
# 建立必要目錄與使用者
mkdir -p /srv/www/htdocs
mkdir /var/log/lighttpd
touch /var/log/lighttpd/access.log /var/log/lighttpd/error.log
useradd lighttpd
chown -R lighttpd:lighttpd /var/log/lighttpd
# lighttpd.conf
server.use-ipv6 = "disable"
# conf.d/fastcgi.conf
fastcgi.server = ( ".php" => (
"localhost" => (
"host" => "127.0.0.1",
"port" => 9999,
"check-local" => "disable"
)
))
cd /srv/www/htdocs
echo '' > index.php
/usr/local/sbin/lighttpd -f /usr/src/lighttpd-1.4.28/doc/config/lighttpd.conf
瀏覽 https://localhost/ 應顯示 PHP 資訊頁。
spawn-fcgi 或 php-fpm 管理 FastCGI 進程池fastcgi.max-procs、fastcgi.min-procs 動態調整logrotate 管理存取/錯誤日誌mod_compress、mod_expire 優化靜態資源