2025年4月22日 星期二

【Ubuntu】手動建置lighttpd+FastCGI環境

compile-and-install-lighttpd.md

lighttpd

安裝相依套件

sudo apt-get install autoconf sudo apt-get install automake sudo apt-get install libtool sudo apt-get install m4 sudo apt-get install pkg-config sudo apt-get install libpcre2-dev sudo apt-get install zlib1g-dev

抓取原始碼

git clone https://git.lighttpd.net/lighttpd/lighttpd1.4.git cd lighttpd1.4 git pull

編譯及安裝

  1. In generic PC platform.
cd lighttpd1.4 ./autogen.sh ./configure -C --prefix=/usr/local # ./configure --help for additional options make -j 32 sudo make install
  1. Cross-compiling with arm platform, add toolchain prefix(such as arm-linux) in configure stage.
./configure --build=arm-linux --host=x86_64-pc-linux-gnu --prefix=/usr/local --disable-static --enable-shared

執行及測試

  1. Create lighttpd.conf like following.
server.document-root = "/tmp" server.bind = "127.0.0.1" server.port = 8080 mimetype.assign = (".txt" => "text/plain", ".html" => "text/html" )
  1. Create a simple file to serve:
echo "Hello World!" > /tmp/hello.txt
  1. Running lighttpd
lighttpd -D -f lighttpd.conf & #Run in background
  1. Visit http://127.0.0.1:8080/hello.txt

FastCGI

Install build requires

sudo apt-get install gcc make m4 autoconf automake libtool

Build code

./autogen.sh ./configure make make install

Running sample code with lighttpd

  1. Create lighttpd.conf like following.
server.document-root = "/tmp" server.bind = "127.0.0.1" server.port = 8080 mimetype.assign = (".txt" => "text/plain", ".html" => "text/html" ) server.modules += ( "mod_fastcgi" ) fastcgi.debug = 1 fastcgi.server = (   "/echo-x" => ((     "bin-path" => "/home/jeff/fcgi2/examples/echo-x",     "socket" => "/tmp/echo-x.sock",     "check-local" => "disable",     "max-procs" => 2,   )) )
  1. Running lighttpd
lighttpd -D -f lighttpd.conf & #Run in background
  1. Visit http://127.0.0.1:8080/echo-x