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

lighttpd

安裝相依套件

1
2
3
4
5
6
7
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

抓取原始碼

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

編譯及安裝

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

執行及測試

  1. Create lighttpd.conf like following.

    1
    2
    3
    4
    server.document-root = "/tmp" 
    server.bind = "127.0.0.1"
    server.port = 8080
    mimetype.assign = (".txt" => "text/plain", ".html" => "text/html" )
  2. Create a simple file to serve:

    1
    echo "Hello World!" > /tmp/hello.txt
  3. Running lighttpd

1
lighttpd -D -f lighttpd.conf & #Run in background
  1. Visit http://127.0.0.1:8080/hello.txt

FastCGI

Install build requires

1
sudo apt-get install gcc make m4 autoconf automake libtool

Build code

1
2
3
4
./autogen.sh
./configure
make
make install

Running sample code with lighttpd

  1. Create lighttpd.conf like following.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    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,

      ))

    )
  2. Running lighttpd
    1
    lighttpd -D -f lighttpd.conf & #Run in background
  3. Visit http://127.0.0.1:8080/echo-x