Following what's described here --- https://httpd.apache.org/docs/2.4/howto/cgi.html --- I've created a tiny Perl document:
#!/usr/bin/perl
print "Content-Type: text/html; charset=utf-8\n\n";
print "Hello, World.";
and called it first.pl
. I've also modified it so that it looks like
#!/usr/bin/perl
print "Content-Type: text/html; charset=utf-8\r\n\r\n";
print "Hello, World.";
because a friend pointed out that the meaning of "\n" is system-dependent, and what's required is CR-LF CR-LF, but the results are the same.)
When I look at localhost/~mylogin/first.pl
from the Chrome browser I get the following output:
Content-Type: text/html; charset=utf-8
Hello, World.
(The ; charset=...
stuff is a slight modification of what the Apache docs suggest, because leaving it off also produced a Content-Type line of output, and some searching suggested that the charset thing might be important. As it happened, it made no difference.)
The references Apache docs say "wherever you put your file, you will see the one line Hello, World.
appear in your browser window. "
Clearly, I'm seeing two lines, the first of which should have been merely treated as description of the remaining content, and I think that's a problem.
I'm hoping that this is some really basic mistake, and would appreciate any suggestions.
Context
I'm on a Mac running Monterey 12.6.6
I got started following instructions from here.
Starting from the vanilla httpd.conf
file, I've made just a few edits, uncommenting
the following:
LoadModule perl_module libexec/apache2/mod_perl.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf
And in /etc/apache2/extra/httpd-userdir.conf
, I've uncommented
Include /private/etc/apache2/users/*.conf
I've created /etc/apache2/users/mylogin.conf
, and given it this content:
<Directory "/Users/mylogin/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
PerlHandler ModPerl::Registry
Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride None
Require host localhost
</Directory>
I've run
chmod +a "_www allow execute" ~
[in all cases above, I've replaced "mylogin" with my actual login, of course]
And then, following instructions from Apache, I added this to the httpd.conf
file:
<Directory "/Users/mylogin/Sites">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>