lighttpd+php(fastcgi) 移植到arm-linux
嵌入式常見的WebServer有:GoAhead,Boa,Lighttpd,Shttpd,Th ttpd,Mathopd,Minihttpd,Appweb。
Boa是一個非常小巧的Web服務器,可執行代碼只有約60KB。它是一個單任務Web服務器,只能依次完成用戶的請求,而不會fork出新的進程來處理并發連接請求。但Boa支持CGI,能夠為CGI程序fork出一個進程來執行。Boa的設計目標是速度和安全,在其站點公布的性能測試中,Boa的性能 要好于Apache服務器。
環境:ubuntu+arm-none-linux-gnueabi-gcc
1、下載并編譯lighttpd-1.4.32
../../lighttpd-1.4.32/configure --host=arm-none-linux-gnueabi \
--prefix=$(pwd)/../../out/target/opt/web --build=i386 --enable-shared --disable-FEATURE --enable-shared --disable-static --disable-lfs --disable-ipv6 --without-PACKAGE --without-valgrind --without-openssl --without-kerberos5 --without-pcre --without-zlib --without-bzip2
--without-lua
make && make install
順利編譯成功后,會在./out/target/opt/web里面生成3個路徑
./out/target/opt/web$ ls
lib sbin share
把生成的東西都拷貝到目標板的路徑里
#sudo cp ./web/* 目標板/opt/web/ -a
2、下載并編譯php-5.5.5
配置和編譯:此處為最簡易的版本,disable掉了所有的擴展模塊;
--prefix=$(pwd)/../../out/target/opt/php --datadir=$(pwd)/../../out/target/opt/php/data --enable-shared --disable-FEATURE --enable-shared --disable-all
如果忘記開啟mb_string:注意項配置php
./configure --host=arm-hisiv400-linux --prefix=/opt/php_install --with-libxml-dir=/opt/libxml_install --with-zlib-dir=/opt/zlib1-2-11/_install --enable-mbstring
make && make install
$ ls
php
把生成的結果放到目標板
cp ./php/bin/php-cgi 目標板/opt/web/sbin/
3、配置lighttpd使得支持php
3.1、在/opt/web/下創建cache、cgi-bin、config、log、sockets、upload、vhosts、webpages等路徑,把lighttpd-1.4.32/doc/config路徑里面的conf.d lighttpd.conf modules.conf拷貝到 目標板/opt/web/config。
3.2. 修改剛復制過來的lighttpd.conf文件
1)將16行至20行修改為如下所示:
var.log_root = "/opt/web/log"
var.server_root = "/opt/web"
var.state_dir = "/opt/web"
var.home_dir = "/opt/web"
2)將61行和93行修改為如下所示:
server.use-ipv6 = "disable"
3)將104和105行注釋掉,如下所示:
#server.username = "lighttpd"
#server.groupname = "lighttpd"
var.conf_dir = "/opt/web/config"
4)將115行修改為如下所示:
server.document-root = server_root + "/webpages"
5)將127行注釋掉,如下所示:
#server.pid-file = state_dir + "/lighttpd.pid"
6)如果不需要查看錯誤日志文件,可以將141行注釋掉,如下所示:
#server.errorlog = log_root + "/error.log"
7)將152行、158行、191行注釋掉,如下所示:
#include "conf.d/access_log.conf"
#include "conf.d/debug.conf"
#server.network-backend = "linux-sendfile"
8)根據系統資源設置207行和225行的數值,本系統的設置分別如下褐色加粗字體所示:
server.max-fds = 256
server.max-connections = 128
9)將314至316行注釋掉,如下所示:
#$HTTP["url"] =~ "\.pdf$" {
# server.range-requests = "disable"
#}
10)將373行修改為如下所示:
server.upload-dirs = ( "/opt/web/upload" )
3.3. 修改剛復制過來的modules.conf文件
1)找到43行,將光標定位到逗號后面,回車,插入如下內容:
"mod_alias",
2)使能fastcgi模塊,將132行的注釋符去掉,如下所示:
include "conf.d/fastcgi.conf"
3.4. 修改剛復制過來的conf.d/fastcgi.conf文件
在server.modules += ( "mod_fastcgi" )下面添加如下:
".php" =>
( "localhost" =>
(
"socket" => "/opt/web/lighttpd.player.server.socket",
"bin-path" => "/opt/php/bin/php-cgi",
"max-procs" => 1,
"check-local" => "disable"
))
)
##
4、添加1個html文件和1個php文件到webpages路徑下
<html>
<head>
<title>broadeng-updatepage-for-bell</title>
</head>
<body>
<form ENCTYPE="multipart/form-data" ACTION="updatefile.php3" METHOD="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
<div align="center"><center> ????è????t:
<input NAME="userfile" TYPE="file">
<input TYPE="submit" VALUE="Send File">
</center></div>
</form>
</body>
</html>
test.php
phpinfo();
?>
5、 啟動lighttpd服務器
./lighttpd -m /opt/web/lib -f ../config/lighttpd.conf
6、打開pc瀏覽器
輸入測試:http://192.168.1.129/
輸入測試:http://192.168.1.129/test.php