'Apache sends script from cgi-bin directory as plain text

This is on FreeBSD 11.3, with Apache 2.4 freshly installed via pkg.

As the minimal possible test of CGI, I'm trying to get the test-cgi script distributed as part of the Apache package for FreeBSD to run. (Serving static HTML pages works fine.)

I'm using the default directories, so the cgi-bin directory is /usr/local/www/apache24/cgi-bin. I have put a shebang for /bin/sh into the test-cgi file, and I have set the protection of the test-cgi file to 755. I can run the test-cgi file from the command line.

I have started Apache running.

I have checked that the config points the script alias directory to the right place:

ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"

I have checked the Directory block in the config for that directory and even tried adding some things (which didn't help):

<Directory "/usr/local/www/apache24/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    AddHandler cgi-script .cgi
    Require all granted
</Directory>

When I put the URL for that script into my browser, I get the source file for the script as text, rather than the output from running the script. That source includes the shebang line I added, which confirms that the URL points to the file on the server that I expect it to.

I've read many articles, all of which suggest things I've checked and have correct. (I've been running Apache since I stopped running the NCSA web server, back in the day; but the last decade I haven't been doing clean installs on systems I have root on mostly, so I'm in danger of having out-of-date knowledge, sometimes worse than ignorance.)

No errors are logged when this happens. In the access log, I get a 304 error followed by a 200:

192.168.1.14 - - [15/Feb/2022:17:45:42 -0600] "GET /cgi-bin/test-cgi HTTP/1.1" 304 -
192.168.1.14 - - [15/Feb/2022:18:00:24 -0600] "GET /cgi-bin/test-cgi HTTP/1.1" 200 1269

That ought to mean something useful, I would think? The 304 is a "not modified" status, which should be returned on a conditional request. This is probably somehow relevant? If I update the file timestamp it doesn't change this, though.

This has got to be something really simple, perhaps even stupid, that I'm overlooking. Would somebody please point out what precise stupid thing it is? Thanks!!



Solution 1:[1]

Got it! In the default config the LoadModule commands for cgi_module and cgid_module were commented out.

Uncommenting them (only one is actually loaded due to surrounding <ifModule> code) got the CGI working normally.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Csala