OK, I think I’ve figured out at least part of what is wrong.
Conclusion:
The Debian apache-netcgi module appears to be built wrong (doesn’t export symbols) and in any case, the config-file is out-of-date and doesn’t refer to the right symbol (even if it were exported)
I’ve never used netcgi2, but apparently you create a findlib package with your CGI in it – no idea how that’s supposed to be structured – and then by specifying it in the NetCgiRequire
line, you get that module loaded and then I guess somehow it gets connected to the right URL-path prefix.
NOTE WELL: I built my own netcgi2 SO module, inside an opam switch. So that means that I didn’t need to use the Debian-installed OCaml.
===========================
Explanation of debugging
- As I wrote before, if you’re going to use the debian-created
netcgi2
Apache module, that’s going to link in the Debian-created OCaml, and that means you’re committed to the Debian installation of OCaml. Probably there’s some way to mix-and-match with another OCaml installation, but it’s going to be dicey.
→ And note that this kind of thing isn’t only endemic to OCaml: it also happens with Rust (and is well-documented, btw). So when you use Rust, you need to make sure that everything was compiled by the same version of rustc.
- So I installed the debian-created
libapache2-mod-netcgi-apache
and observed the same error you did:
$ sudo /usr/sbin/apachectl configtest
apache2: Syntax error on line 146 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/netcgi_apache.load: Can't locate API module structure `netcgi_apache_module' in file /usr/lib/apache2/modules/mod_netcgi_apache.so: /usr/lib/apache2/modules/mod_netcgi_apache.so: undefined symbol: netcgi_apache_module
Action 'configtest' failed.
The Apache error log may have more information.
Notice I used configtest, which is enough to elicit the error.
- Next, let’s “nm” the SO file … and we find that it exports no symbols. None at all. Now, I’m no longer an expert on how shared-libraries work, but I think that this is a problem
→ THIS IS PROBABLY A BUG in the Debian module
- So then I downloaded ocamlnet and built it (this entailed installing
apache2-dev
, etc) so I could build:
./configure -enable-apache -apache usr/sbin/apache2
Note that this isn’t the default build-setup. Since Gerd wrote all this stuff prior to the arising of opam, he obviously wouldn’t set ocamlnet to automatically try to build the apache module … when apache might not even be installed on the machine.
- And then ran “nm” on the built SO file:
$ nm -B mod_netcgi_apache.so | grep module
000000000002a040 D netcgi_module
- And so we see the entrypoint of this SO. Let’s modify the module-load command above (in
/etc/apache2/mods-enabled/netcgi_apache.load
to use this SO):
$ cat /etc/apache2/mods-enabled/netcgi_apache.load
#LoadModule netcgi_apache_module /usr/lib/apache2/modules/mod_netcgi_apache.so
LoadModule netcgi_module /home/chet/Hack/Camlp5/src/lib-ocamlnet3/code/src/netcgi2-apache/mod_netcgi_apache.so
NetcgiRequire netcgi2-apache
And now when we run that configtest:
$ sudo /usr/sbin/apachectl configtest
[Sat Jan 14 14:44:00 2023] [Netcgi_apache_mod] No such ocaml package: netcgi2-apache
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK
- I wonder what that error-message is?
~/Hack/Camlp5/src/lib-ocamlnet3/code/src/netcgi2-apache$ grep 'No such' *
grep: mod_netcgi_apache.so: binary file matches
grep: netcgi2-apache.cma: binary file matches
grep: netcgi_apache.cmo: binary file matches
netcgi_apache.ml: "No such script.")) in
netcgi_apache.ml: "No such script.")) in
grep: netcgi_apache_mod.cmo: binary file matches
netcgi_apache_mod.ml: log_error ("No such ocaml package: " ^ name)
netcgi_apache_mod.ml.in: log_error ("No such ocaml package: " ^ name)
So it’s an error-message from OCaml code, saying that some OCaml findlib module isn’t present. This means that we’ve successfully booted-up the OCaml container under Apache, and it can’t find the application.
I’ll stop here.