lighttpd + PHP FastCGI 架構以輕量、高併發著稱。以下為完整編譯安裝筆記(Linux 環境),供參考驗證。
./configure --prefix=/data2/ali --enable-assembler --enable-thread-safe-client --without-debug
make && make install
tar zxf mysql-standard-5.0.27-linux-i686-glibc23.tar.gz
cp -rf mysql-standard-5.0.27-linux-i686-glibc23 /usr/local/mysql
mkdir -p /data2/ali/mysql3308 /data2/ali/mysql3309
/scripts/mysql_install_db --ldata=/data2/ali/mysql3308
cp support-files/my-medium.cnf /data2/ali/mysql3308/my.cnf
# 修改 my.cnf:datadir、port=3308、socket=/tmp/mysql-3308.sock
# 同理複製並修改 3309 實例
# 啟動
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data2/ali/mysql3308/my.cnf --user=root &
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data2/ali/mysql3309/my.cnf --user=root &
# 驗證
ps -ax | grep mysql
mysql -S /tmp/mysql-3308.sock
tar zxf php-5.2.4.tar.gz
cd php-5.2.4
./configure \
--prefix=/usr/local/php-fcgi \
--enable-fastcgi \
--enable-force-cgi-redirect \
--without-iconv \
--enable-mbstring \
--with-mysql=/usr/local/mysql
make && make install
cp php.ini-dist /usr/local/php-fcgi/lib/php.ini
# 驗證 FastCGI
/usr/local/php-fcgi/bin/php-cgi -v
# 輸出含 "PHP 5.2.4 (cgi-fcgi)" 即成功
# 1. 建立執行用戶
groupadd lighttpd
useradd -g lighttpd -s /sbin/nologin -d /dev/null lighttpd
# 2. 編譯安裝
wget https://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
tar -zxvf lighttpd-1.4.8.tar.gz
cd lighttpd-1.4.8
./configure --prefix=/usr/local/lighttpd
make && make install
mkdir /usr/local/lighttpd/conf /usr/local/lighttpd/log
mv ./doc/lighttpd.conf /usr/local/lighttpd/conf/
cp ./doc/rc.lighttpd.redhat /etc/init.d/lighttpd
server.modules = (
"mod_rewrite", "mod_redirect", "mod_access", "mod_fastcgi"
)
fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/var/run/lighttpd/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php-cgi" # 關鍵:指向 php-cgi 而非 php
)
)
)
避坑指南:bin-path 必須指向 php-cgi,指向 php 會報錯。
/usr/local/lighttpd/sbin/lighttpd -f conf/lighttpd.conf
# 在網站根目錄建立 test.php 驗證