- Table of contents
- InstallFromSource
InstallFromSource¶
source browser¶
View source code in the lighttpd 1.4 git repository
source checkout¶
There are multiple options to obtain a lighttpd source tree. git is recommended.
- git: (recommended)
read-only:$ git clone https://git.lighttpd.net/lighttpd/lighttpd1.4.git
developer:$ git clone git+ssh://git@lighttpd.net/lighttpd/lighttpd1.4.git
# initial checkout git clone https://git.lighttpd.net/lighttpd/lighttpd1.4.git cd lighttpd1.4 # subsequent updates (to obtain latest source) #cd lighttpd1.4 git pull
- svn: (alternative to git)
# initial checkout svn checkout https://github.com/lighttpd/lighttpd1.4/trunk lighttpd1.4 cd lighttpd1.4 # subsequent updates (to obtain latest source) #cd lighttpd1.4 svn update
- source release/snapshot
https://download.lighttpd.net/lighttpd/# download and extract tarball latest=$(curl -s https://download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt) curl -o "$latest.tar.xz" https://download.lighttpd.net/lighttpd/releases-1.4.x/"$latest.tar.xz" tar -xJf "$latest.tar.xz" cd $latest
build prerequisites¶
lighttpd supports multiple build frameworks: automake, cmake, meson, and scons.
Ensure you have installed the latest development tools and packages available, e.g. for automake:- autoconf
- automake
- libtool
- m4
- pcre-devel / libpcre3-dev
- pkg-config
- openssl
- gnutls
- mbedtls
- nss
- wolfssl
Further details can be found in lighttpd INSTALL (Please read)
Depending on which features you want, other development libraries may be needed: OptionalLibraries
On most systems you need to install the development version of the library packages; the library itself will not be enough!
On debian you can also use apt-get to install all lighttpd build dependencies: apt-get build-dep lighttpd
build commands (examples)¶
automake
#cd lighttpd1.4 ./autogen.sh ./configure -C --prefix=/usr/local # ./configure --help for additional options make -j 4 make check #sudo make install
cmake
#cd lighttpd1.4 cmake -DCMAKE_INSTALL_PREFIX=/usr/local -Wno-dev . make -j 4 make test #sudo make install
meson
#cd lighttpd1.4 meson setup --buildtype debugoptimized --prefix /usr/local build cd build meson compile meson test #sudo meson install
scons
#cd lighttpd1.4 scons -j 4 build_static=1 build_dynamic=0 prefix=/usr/local #sudo scons -j 4 build_static=1 build_dynamic=0 prefix=/usr/local install
Examples commands for more fully-featured builds might reference lighttpd scripts/ci-build.sh
Also, there are more options for running unit tests
cross-compiling¶
automake help: ./configure --help
automake example: ./configure --build=arm-linux --host=x86_64-pc-linux-gnu --prefix=/usr/local --disable-static --enable-shared
How-To: build lighttpd for iOS on arm64
distro packaging (external examples)¶
Debian: debian/control
Fedora: lighttpd.spec
OpenWRT: net/lighttpd/Makefile
Debian: current packages: https://debian.lighttpd.net/
Debian: build package for older Debian systems using Debian `dpkg-buildpackage`
(The commands below assume that debian/changelog matches the latest lighttpd release. Change $release
as appropriate.)
release=$(curl -s https://download.lighttpd.net/lighttpd/releases-1.4.x/latest.txt) release=${release#*-} wget https://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-$release.tar.xz mv lighttpd-$release.tar.xz lighttpd_$release.orig.tar.xz git clone https://salsa.debian.org/debian/lighttpd.git cd lighttpd/ # For older Debian releases: head -1 debian/changelog # For older Debian releases: git checkout debian/1.4.76-1 # For older Debian releases: edit top line of debian/changelog to match top line from `head -1 debian/changelog` above dpkg-buildpackage -uc -us cd .. ls lighttpd*_$release*.deb # dpkg -i ...
To build on older Debian releases without
debputy
, checkout an older tag from salsa.debian.org/debian/lighttpd.git, then modify the top line of debian/changelog to match the $release
version
running lighttpd from build tree¶
lighttpd can be run from the build tree, without needing to install it. This is useful for testing. In the shell in which you built lighttpd, chdir to the top of the source tree (if not already there).
Create a basic lighttpd.conf to listen on localhost port 8080 and serve files from /tmp
(not recommended for production use!):
server.document-root = "/tmp" server.bind = "127.0.0.1" server.port = 8080 mimetype.assign = (".txt" => "text/plain", ".html" => "text/html" )
Create a simple file to serve:
echo "Hello World!" > /tmp/hello.txt
Run lighttpd in the foreground:
src/lighttpd -D -f lighttpd.conf -m $PWD/src/.libs
In a different shell:
curl http://127.0.0.1:8080/hello.txt
In the shell running lighttpd, press press
Ctrl-C
to cause lighttpd to exit.
Since lighttpd 1.4.60, the lighttpd config can optionally be specified on stdin (though incompatible with one-shot mode (-1
))echo -e 'server.document-root="/tmp"\n server.port=8080' | src/lighttpd -D -m $PWD/src/.libs -f -
Since lighttpd 1.4.70, a shell HERE doc can optionally be used to specify the lighttpd config
src/lighttpd -D -m $PWD/src/.libs -f <(cat <<END server.document-root = "/tmp" server.port = 8080 END )
signals¶
lighttpd responds to the following signals:
- SIGTERM - shut down immediately (terminate existing connections, then exit)
- SIGINT - shut down gracefully (serve existing connections, then exit)
- SIGUSR1 - reload gracefully (serve existing connections, then reload config)
- SIGHUP - re-open log files (NOTE: does not reload lighttpd configuration)
(Note: SIGUSR1 behavior is available in lighttpd 1.4.46 and later)
graceful restart¶
With lighttpd 1.4.46 and later, SIGUSR1 is the recommended method to gracefully handle configuration reloads, though a graceful stop and then restart of lighttpd is still required for lighttpd configurations which chroot.
With lighttpd 1.4.56 and later, graceful restart can have a time limit applied to existing active connections before the server reloads the config: (server.feature-flags)server.feature-flags = ( "server.graceful-shutdown-timeout" => 5 )
In some configurations, lighttpd can immediately restart, while a forked copy of the server continued to serve existing connections (YMMV):server.feature-flags = ( "server.graceful-shutdown-timeout" => 5, "server.graceful-restart-bg" => "enable" )
server.systemd-socket-activation = "enable"
archive: older article from 2005 talks about graceful restart using SIGINT: https://blog.lighttpd.net/articles/2005/09/02/graceful-restart/
initscripts¶
Depending on the operating system and distribution brand, there are many ways to set up lighttpd to run as a daemon when the system starts up, and to send signals to lighttpd for start/stop/restart/etc. Rather than attempting to maintain scripts for an unknown number of distros, here are links to a few, which can be used as examples.
- Arch: https://github.com/archlinux/svntogit-packages/tree/packages/lighttpd/trunk
- Debian: https://salsa.debian.org/debian/lighttpd
- Fedora: https://src.fedoraproject.org/rpms/lighttpd/tree/rawhide
- FreeBSD: https://cgit.freebsd.org/ports/tree/www/lighttpd
- Gentoo: https://gitweb.gentoo.org/repo/gentoo.git/tree/www-servers/lighttpd/
- openSUSE: https://build.opensuse.org/package/show/server:http/lighttpd
- OpenWRT: https://github.com/openwrt/packages/tree/master/net/lighttpd
sample systemd unit script lighttpd.service
supervise¶
As an alternative to init scripts you can setup a "supervised" lighttpd with daemontools or runit, see LighttpdUnderSupervise
xinetd¶
- Run lighttpd from xinetd, and have lighttpd continue accepting connections, exiting after lighttpd is idle for 10 minutes.
/etc/lighttpd/lighttpd.conf (sample)
server.document-root = "/var/www" server.bind = "/dev/stdin"
/etc/xinetd.d/lighttpd (sample)
service lighttpd { socket_type = stream protocol = tcp port = 80 type = http wait = yes user = lighttpd server = /usr/sbin/lighttpd server_args = -D -f /etc/lighttpd/lighttpd.conf -i 600 }
- Run lighttpd from xinetd, and have lighttpd serve a single connection, including keep-alive requests, and then exit.
/etc/lighttpd/lighttpd.conf (sample)
server.document-root = "/var/www"
/etc/xinetd.d/lighttpd (sample)
service lighttpd { socket_type = stream protocol = tcp port = 80 type = http wait = no user = lighttpd server = /usr/sbin/lighttpd server_args = -D -f /etc/lighttpd/lighttpd.conf -1 }
netcat¶
- Run lighttpd via netcat or ncat or nc
/etc/lighttpd/lighttpd.conf (sample)
server.document-root = "/var/www"
netcat command
ncat -l 8080 -e "/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf -1"
shell pipeline¶
- Run lighttpd in shell pipeline
/etc/lighttpd/lighttpd.conf (sample)
server.document-root = "/var/www"
shell pipeline of one or more requests
printf "GET /index.txt HTTP/1.1\r\nHost: example.com\r\n\r\n" | /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -1
Updated by gstrauss 5 months ago · 38 revisions