_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

cgiUsing CGI with http - Configuration and usage

- The script needs an interpreter (eg.: #!/bin/ksh).
- the first output line needs to be 'echo "Content-type: text/html"'.
- the second output line needs to be empty 'echo ""'.
- copy required binaries (including interpreter) to /var/www/bin/.
- copy dependencies to the corresponding structures in /var/www.
- binaries and libraries must be owned by www.

$ whereis grep
/usr/bin/grep
$ ldd /usr/bin/grep
Start End Type Open Ref GrpRef Name
0000030be12e4000 0000030be12ef000 exe 1 0 0 /usr/bin/grep
0000030e32295000 0000030e322b3000 rlib 0 1 0 /usr/lib/libz.so.6.0
0000030eb72e8000 0000030eb73dd000 rlib 0 1 0 /usr/lib/libc.so.96.1
0000030de67ed000 0000030de67ed000 ld.so 0 1 0 /usr/libexec/ld.so
$ doas install -o www /usr/lib/libz.so.6.0 /var/www/usr/lib/
$ doas install -o www /usr/libexec/ld.so /var/www/usr/libexec/

The location with the cgi scripts needs to have the fastcgi socket defined.

server default {
	...
	location "/$CGI_PATH/*" {
		fastcgi socket "/run/slowcgi.sock"
	}
}

This site has the location "/:*" defined and when accessing from curl it will display the ascii version of the files.

location /:* {
	fastcgi { param SCRIPT_FILENAME "$CGI_PATH_FROM_CHROOT/$SCRIPT"}
 }

server default {
	listen on * port 80
	root "/htdocs/$DIR"
	location "/$CGI_PATH/*" {
		fastcgi socket "/run/slowcgi.sock"
	}
	#curl access
	location "/:*" {
		fastcgi { param SCRIPT_FILENAME "$CGI_PATH_FROM_CHROOT/$SCRIPT"}
	}
}

(back to top)

chroot /var/www to test the script and ensure all dependencies are available and have the correct permissions.

(back to top)

  1. Test:
    doas slowcgi -dnvvv
  2. Enable and start
    doas rcctl enable slowcgi
    doas rcctl restart slowcgi
  3. Restart httpd.

(back to top)

When upgrading the system all binaries and dependencies need to be updated.

(back to top)

web, httpd
examples: figlet example cgi, search
text files: </dev/example.cgi> , </dev/curl.cgi> , </dev/search.cgi>
OpenBSD manpages: slowcgi(8), rcctl(8)
links
- Serving Fossil via httpd on OpenBSD

(back to top)

2026-07-12 : Translated to Spanish.
  Added upgrade information.
2025-10-03 : Created.

(back to top)

ohazot | about | ohazot.com <admin@ohazot.com>

This document applies to: OpenBSD 7.7 | 2026-07-12