這裡以FreeBSD的ports安裝為例,其他OS應該也是差不多,
lighttpd目前似乎沒有windows的版本。
1.安裝 www/php5-cgi 或者 www/php4-cgi,我是安裝php5-cgi,底下是我的 make config 選項
[X] REDIRECT Enable force-cgi-redirect support
[X] DISCARD Enable discard-path support
[X] FASTCGI Enable fastcgi support
[X] PATHINFO Enable path-info-check support
[X] MULTIBYTE Enable zend multibyte support
2.安裝www/lighttpd 我的選項是
[X] MYSQL Enable MYSQL support
[X] CML Enable Cache Meta Language support
3 安裝 lang/php5-extensions
把一些會用到的 php module 安裝進去
如果不要用的話,再到 /usr/local/etc/php/extensions.ini
把不要用的註解掉就好了。(載入越多module你的php就會越耗記憶體)
4. lighttpd 比較特殊的是 它需要用 phpx-cgi 而不是一般apache使用的 mod_php
所以我是把 apache2 移除 , mod_php 移除 , phpX-*extensons 移除通通重裝。
在 FreeBSD 下面,可以移除 mod_phpX ,裝 php5-cgi 後,
再用 php5-extensions 來重新安裝extenstions
5.再來是 lighttpd 設定的部份 "/usr/local/etc/lighttpd.conf"
我 enable 的 module 有
"mod_rewrite", "mod_alias", "mod_access", "mod_fastcgi", "mod_rrdtool", "mod_accesslog"
server.document-root = "/home/plog/" ##請改成你的lifetype位置
server.errorlog = "/var/log/lighttpd.error.log" ##請自行 touch一個,再chown www:www
index-file.names = ( "summary.php", "index.php", "index.html", "index.htm", "default.htm" )
accesslog.filename = "/var/log/lighttpd.access.log" #跟errorlog一樣,請自行touch一個再chown
## 這是因為 /home/plog/tmp 是不可以被讀取的,等同於之前在 /home/plog/tmp下的.htaccess的
$HTTP["url"] =~ "/tmp" {
url.access-deny = ( "" )
}
fastcgi.map-extensions = ( "/album" => ".php", "/post" => ".php", "/archives" => ".php", "/static" => ".php", "/rss" => ".php", "/category" => ".php", "/trackbacks" => ".php", "/comment" => ".php", "/resource" => ".php", "/get" => ".php", "/blog" => ".php", "/user" => ".php" )
## 這些是因為 /home/plog下有些檔案,要用php的方式去處理,而不是下載回來,要設定不然,像是相簿、資料夾就無法使用
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/bin/php",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "5",
"PHP_FCGI_MAX_REQUESTS" => "1000"
),
"bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
"broken-scriptfilename" => "enable"
)
)
) ##這些是我目前 php-fastcgi的設定,跟你server的負荷能力有關
url.rewrite= (
"^([0-9]+)_[^/]+/archive/([0-9]{6}).html$" => "index.php?blogId=$1&Date=$2",
"^([0-9]+)_[^/]+/albums/([0-9]+)_[^.]+.html$" => "index.php?op=ViewAlbum&blogId=$1&albumId=$2",
"^([0-9]+)_[^/]+/albums/$" => " index.php?op=ViewAlbum&blogId=$1&albumId=0",
"^([0-9]+)_[^/]+/categories/([0-9]+)_[^.]+.html$" => "index.php?blogId=$1&postCategoryId=$2",
"^([0-9]+)_[^/]+/feeds/categories/([0-9]+)_[^.]+/(.*)$" => "rss.php?blogId=$1&categoryId=$2&profile=$3",
"^([0-9]+)_[^/]+/feeds/(.*)$" => "rss.php?blogId=$1&profile=$2",
"^([0-9]+)_[^/]+/trackbacks/([0-9]+)_[^.]+.html$" => "index.php?op=Trackbacks&blogId=$1&articleId=$2",
"^([0-9]+)_[^/]+/comment/([0-9]+)_[^.]+.html$" => "index.php?op=Comment&blogId=$1&articleId=$2",
"^([0-9]+)_[^/]+/resources/([^.]+).([^.]+).html$" => "index.php?op=ViewResource&blogId=$1&resource=$2.$3",
"^([0-9]+)_[^/]+/(.+)$" => "index.php?op=Template&blogId=$1&show=$2",
"^([0-9]+)(_[^/]+)?$" => "index.php?blogId=$1",
"^([0-9]+)_[^/]+/archive/([0-9]{8}).html$" => "index.php?blogId=$1&Date=$2",
"^([0-9]+)_[^/]+/get/(.+)$" => "resserver.php?blogId=$1&resource=$2")
##這些是我的url-rewrite規則,目前看起來沒什麼問題,我過因為我使用的是自訂網址,不確定一般網址會怎樣
其實 lighttpd 的設定檔很人性化,一下子就懂了,re-write rule也是。
比對一下 /home/plog/下的 .htaccess 再改過來 lighttpd 的格式就好了
他的特色是對於 static page的處理超強,有支援串流格式 (flv),省資源。
在Linux下當web server效能很棒。試試看吧!
大概要注意的就是 phpX-cgi , lighttpd 的re-write rule, php-fastcgi在lighttpd 下的設定
當 lighttpd cache起來的時候,速度超快的!