易春木

Feed Rss

openwrt-lighttpd support PHP with fastcgi

08.30.2010, IT開發, 記事本, by , 1,219 人次 .

cross-compile的環境是OpenWrt的kamikaze_8.09程式碼:
1.安裝lighttpd:
在kamikaze_8.09根目錄下指令 make menuconfig
=>Network => Web => lighttpd

³ <*>   lighttpd-mod-fastcgi...................................... FastCGI module

2.安裝PHP5:
在kamikaze_8.09根目錄下指令 make menuconfig
=>Languages => PHP

³ ³ < >   php5-cgi............................... PHP5 Hypertext preprocessor (CGI)                                         ³ ³
³ ³ < >   php5-cli............................... PHP5 Hypertext preprocessor (CLI)                                         ³ ³
³ ³ <*>   php5-fastcgi....................... PHP5 Hypertext preprocessor (FastCGI)                                         ³ ³
³ ³ < >   php5-mod-apc............................................... APC Extension                                         ³ ³
³ ³ < >   php5-mod-curl................................................ cURL module                                         ³ ³
³ ³ < >   php5-mod-exif............................................. EXIF Extension                                         ³ ³
³ ³ < >   php5-mod-ftp.................................................. FTP module                                         ³ ³
³ ³ < >   php5-mod-gd........................................... GD graphics module                                         ³ ³
³ ³ < >   php5-mod-gmp.................................................. GMP module                                         ³ ³
³ ³ < >   php5-mod-ldap................................................ LDAP module                                         ³ ³
³ ³ < >   php5-mod-mysql.............................................. MySQL module                                         ³ ³
³ ³ < >   php5-mod-openssl.......................................... OpenSSL module                                         ³ ³
³ ³ < >   php5-mod-pcre................................................ PCRE module                                         ³ ³
³ ³ < >   php5-mod-pdo..................................... PHP Data Objects module                                         ³ ³
³ ³ < >   php5-mod-pgsql......................................... PostgreSQL module                                         ³ ³
³ ³ <*>   php5-mod-session.......................................... Session module                                         ³ ³
³ ³ <*>   php5-mod-sockets.......................................... Sockets module

3.修改 kamikaze_8.09/package/feeds/packages/lighttpd/Macfile

define Package/lighttpd/install
$(INSTALL_DIR) $(1)/etc
$(INSTALL_DATA) ./files/lighttpd.conf $(1)/etc/
$(INSTALL_DIR) $(1)/etc/default
$(INSTALL_DATA) ./files/lighttpd.default $(1)/etc/default/lighttpd
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/lighttpd.init $(1)/etc/init.d/lighttpd
$(INSTALL_DIR) $(1)/usr/lib/lighttpd
$(INSTALL_DIR) $(1)/www <====( add this row)
for m in dirlisting indexfile staticfile; do \
$(CP) $(PKG_INSTALL_DIR)/usr/lib/lighttpd/mod_$$$${m}.so $(1)/usr/lib/lighttpd/ ; \
done
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/lighttpd $(1)/usr/sbin/
cp -rf $(PKG_BUILD_DIR)/tests/docroot/www/* $(1)/www <====( add this row)
endef

4.修改 kamikaze_8.09\package\feeds\packages\lighttpd\files\lighttpd.conf

(1)server.modules中把下面行的”#” 去掉
                           “mod_fastcgi”,

server.modules = (
#    'mod_rewrite',
#    'mod_redirect',
#    'mod_alias',
#    'mod_auth',
#    'mod_status',
#    'mod_setenv',
'mod_fastcgi',
#    'mod_proxy',
#    'mod_simple_vhost',
#    'mod_cgi',
#    'mod_ssi',
#    'mod_usertrack',
#    'mod_expire'
)

ps: 勿enable cgi, 不然會造成fcgi無法work

(2)index-file.names中修改:

index-file.names = ( 'index.php', 'index.html', 'default.html', 'index.htm', 'default.htm' )

(3)server.port中修改port號為8081 (可改可不改)

server.port             = 8080

(4)fastcgi.server中,把'#'去掉, 并修改bin-path .

fastcgi.server = ( '.php' => ((
'bin-path' => '/usr/bin/php-fcgi',
'socket' => '/tmp/php-fastcgi.socket'
)))

5.編譯囉! 完成後,應該可以看的懂.php檔了

6.開機如果沒有自動執行, 請輸入

killall lighttpd   (刪除執行中的lighttpd程序)

lighttpd -f /etc/lighttpd.conf     (重新啟動lighttpd程序)

PS: 驗證是否支援fastcgi:

input# 

$ php-fcgi -v

output #

 
PHP 5.0.4 (cgi-fcgi) (built: Nov  8 2005 08:25:54)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies

參考資料:

Lighttpd PHP fastcgi configuration   http://www.cyberciti.biz/tips/lighttpd-php-fastcgi-configuration.html

閱讀這篇文章的讀者也會看:

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>