2008年4月16日

安裝lighttpd for Windows with Perl

    我的目的是要在Windows上面測試用Perl寫的cgi程式,因為不想用IIS,Apache又有一點肥,剛好在網路上搜尋時,看到了Lighttpd for Windows版本,是由匈牙利人所開發的套件,於是就決定抓下來試試。

  1. 下載Lighttpd

    有兩個版本可以選擇,因為只是要測試用,所以選沒有SSL support的那個套件會比較快,Download site選在USA的mirror站下載會快一點。

  2. 安裝並啟動Lighttpd

    預設是安裝在C:\Program Files\LightTPD,安裝完成後,執行bin\Service-Install.exe,會把Lighttpd安裝成Windows Service。

    完成後,開啟Browser,網址輸入http://localhost,若是有出現Lighttpd的網頁,表示已經安裝成功。

  3. 設定Lighttpd

    在此之前,電腦要先裝好Perl套件,我用的是ActivePerl 5.10.0版,預設是安裝在C:\Perl。

    到C:\Program Files\LightTPD\conf中編輯lighttpd-inc.conf,這個檔案是Lighttpd的主要設定檔,設定如下:

    server.modules = ( 
                                    "mod_access", 
                                    "mod_accesslog", 
                                    "mod_alias",    
                                    "mod_cgi" #將這一行前面的註掉
                              )

    #這邊一定要用絕對路徑,否則在測試CGI時會出現500 Internal Error
    server.document-root  = "C:/Program Files/LightTPD/htdocs/"

    #這邊要把註解拿掉,並且將perl設定至正確的路徑,注意反斜線
    cgi.assign                  = ( ".php" => "PHP/php-cgi.exe",
                                         ".pl"  => "C:/perl/bin/perl.exe",
                                         ".cgi" => "C:/perl/bin/perl.exe"
                                       )

  4. 測試CGI

    在C:\Program Files\LightTPD\htdocs中建立cgi-bin資料夾,我們將cgi程式放在此。
    用下面這一支程式測試,儲存成test.pl放在cgi-bin資料夾中。

    #!/usr/bin/perl
    print "Content-type:text/html\n\n";
    print "Hello ...\n";

    然後用http://localhost/cgi-bin/test.pl測試,若是出現hello文字,表示設定成功了。smile_teeth