webservers-cgi

webserver-cgi: a set of simple CGI-enabled web servers
Login

webserver-cgi: a set of simple CGI-enabled web servers

A set of simple CGI-enabled web servers, with minimal support: HTTP and CGI, that's it.

See the webservers project for static-content-only web servers.
See the notify-portable project for a demo application with an embedded CGI-enabled web server.

Purpose

Try to get a few web servers, found on the net and written in C, to work the way I want:

To check if a web server is portable between OS:es, both POSIX sockets and Winsock sockets should be supported.
To fast-check: If HTTP-CGI server compiles both with MSYS2 (POSIX) and with Mingw64 (Winsock), chances are (big) that the web server works for several other OS:es as well.

CGI-enabled web server: MinGW64: Civetweb

https://github.com/civetweb/civetweb

MinGW64:

wget https://github.com/civetweb/civetweb/archive/master.zip -O civetweb-master.zip
unzip civetweb-master.zip
cd civetweb-master
mingw32-make CC=gcc
###mingw32-make
./civetweb.exe
###cp ../cgi-bin/hellohtml.exe .
###cp ../cgi-bin/hellohtml.exe hellohtml.cgi
###./civetweb.exe -listening_ports 1236 -cgi_pattern '**.exe$|**.cgi'
./civetweb -listening_ports 1234 -document_root ../cgi-bin -cgi_pattern '**.exe$|**.cgi$|**.pl$'

http://127.0.0.1:1236/hellohtml.exe
http://127.0.0.1:1236/hellohtml.cgi

Workaround for Perl scripts (NOTE: makes C programs stop working as CGI): cgi_interpreter

https://github.com/cztomczak/phpdesktop/issues/68

./civetweb.exe -listening_ports 1236 -cgi_pattern '**.exe$|**.cgi|**.pl' -cgi_interpreter '\\usr\\bin\\perl.exe' <-- ERROR

./civetweb.exe -listening_ports 1236 -cgi_pattern '**.exe$|**.cgi|**.pl' -cgi_interpreter '\\c\\msys64\\usr\\bin\\perl.exe' <-- ERROR

./civetweb.exe -listening_ports 1236 -cgi_pattern '**.exe$|**.cgi|**.pl' -cgi_interpreter 'C:\\msys64\\usr\\bin\\perl.exe' <-- OK (for Perl scripts, but not for C)

CGI-enabled web server: MSYS2: Merecat

http://merecat.troglobit.com/

Merecat was the original code for Civetweb (see above).
Merecat works with MSYS2:

wget https://github.com/troglobit/merecat/archive/master.zip -O merecat-master.zip
unzip merecat-master.zip
cd merecat-master
./autogen.sh
mkdir -p build/usr build/var build/etc
./configure --prefix=$PWD/build/usr --localstatedir=$PWD/build/var --sysconfdir=$PWD/build/etc --disable-dirlisting --without-config --without-ssl --without-symlinks --without-zlib
make
make install
build/usr/sbin/merecat.exe -p 8888 -c "**.cgi|**.exe|**.pl|**/cgi-bin/*"
cp ../cgi-bin/hellohtml.exe .

http://127.0.0.1:8888/hellohtml.exe

Other CGI-enabled web servers

CGI-enabled web server: MinGW64: Mongoose

https://github.com/cesanta/mongoose
https://cesanta.com/docs/overview/build-options.html
https://cesanta.com/docs/http/cgi.html
https://cesanta.com/docs/http/server-example.html
https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server

CGI problems with mongoose compiled with MinGW64:

wget https://github.com/cesanta/mongoose/archive/master.zip -O mongoose-master.zip
unzip mongoose-master.zip
patch mongoose-master.patch # Fix casts and call to thread_enabled function 
cd mongoose-master/examples/simplest_web_server

    s_http_server_opts.enable_directory_listing = "no";

Makefile:
----------------------------------------
PROG = simplest_web_server
# MODULE_CFLAGS=-DMG_DISABLE_DAV_AUTH -DMG_ENABLE_FAKE_DAVLOCK
# MODULE_CFLAGS=-DMG_DISABLE_DAV_AUTH -DMG_ENABLE_FAKE_DAVLOCK -DMG_DISABLE_THREADS
#MODULE_CFLAGS=-DMG_DISABLE_DAV_AUTH -DMG_ENABLE_FAKE_DAVLOCK -DMG_ENABLE_THREADS=0
MODULE_CFLAGS=-DMG_DISABLE_DAV_AUTH -DMG_ENABLE_THREADS=0
MODULE_CFLAGS = \
-DMG_DISABLE_DAV_AUTH \
-DMG_ENABLE_FAKE_DAVLOCK \
-DMG_ENABLE_SSL=0 \
-DMG_ENABLE_IPV6=0 \
-DMG_ENABLE_MQTT=0 \
-DMG_ENABLE_MQTT_BROKER=0 \
-DMG_ENABLE_DNS_SERVER=0 \
-DMG_ENABLE_COAP=0 \
-DMG_ENABLE_HTTP=1 \
-DMG_ENABLE_HTTP_CGI=1 \
-DMG_ENABLE_HTTP_SSI=0 \
-DMG_ENABLE_HTTP_SSI_EXEC=0 \
-DMG_ENABLE_HTTP_WEBDAV=0 \
-DMG_ENABLE_HTTP_WEBSOCKET=0 \
-DMG_ENABLE_BROADCAST=0 \
-DMG_ENABLE_GETADDRINFO=0 \
-DMG_ENABLE_THREADS=0 \
-DMG_DISABLE_HTTP_DIGEST_AUTH=1 \
-DCS_DISABLE_SHA1=1 \
-DCS_DISABLE_MD5=1 \
-DMG_DISABLE_HTTP_KEEP_ALIVE=1
include ../examples.mk
----------------------------------------
./simplest_web_server.exe
cp ../../../cgi-bin/hellohtml.exe .

http://127.0.0.1:8000/hellohtml.exe

thttpd

Tiny web server.

http://www.acme.com/software/thttpd/

MSYS2/MinGW64:

wget http://www.acme.com/software/thttpd/thttpd-2.29.tar.gz
tar xvfz thttpd-2.29.tar.gz
cd thttpd-2.29
./configure --host=win32 --prefix=$PWD/build
make <--- ERROR
make install

shttpd

Tiny web server.

https://docs.huihoo.com/shttpd/
https://sourceforge.net/projects/shttpd/files/shttpd/

tar xvfz shttpd-1.42.tar.gz
cd shttpd-1.42
cd src
make unix DNO_SSL=1 DNO_AUTH=1 DNO_SSI=1 DNO_THREADS=1
./shttpd.exe -ports 8889 -cgi_ext "exe,cgi,pl,php"
cp ../../cgi-bin/hellohtml.exe .

http://127.0.0.1:8889/hellohtml.exe

tcgi

https://github.com/ndevilla/tcgi

Depends on a small hash library: https://github.com/ndevilla/dict

git clone https://github.com/ndevilla/tcgi.git
git clone https://github.com/ndevilla/dict.git
cp dict/dict* tcgi/

althttpd

drh's standalone web server

https://sqlite.org/docsrc/doc/trunk/misc/althttpd.md
https://www.sqlite.org/docsrc/file/misc/althttpd.c

In MSYS2 shell:

cd althttpd
gcc -Os -o althttpd althttpd.c # Optimize for size
gcc -g -o althttpd althttpd.c # Debug
make clean all # Debug, using Makefile
./althttpd -root ../cgi-bin -port 9999

mwwwd: CGI-enabled web server for both MinGW64/Win32 and MSYS2/POSIX: Merge Civetweb and althttpd code into one single server mwwwd

Roadmap:
Probably the easiest way is to use althttpd as a base for both MinGW64/Win32 and MSYS2/POSIX.
The parts of althttpd which does not compile, should be replaced by Civetweb code.

TODO: Check these projects