我正在使用Mac OS High Sierra 10.13.06。我 https://discussions.apple.com/docs/DOC-12034 遵循了本指南,但无法使我的perl脚本工作。浏览器只提供下载它。我也尝试加载mod_cgi,但这没有帮助。
sudo apachectl -M
显示已加载perl_module和cgi_module。 这是error_log文件:
[Tue Dec 10 11:02:01.586530 2019] [mpm_prefork:notice] [pid 77] AH00169: caught SIGTERM, shutting down
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MacBook-Air-Nikita.local. Set the 'ServerName' directive globally to suppress this message
[Tue Dec 10 11:02:01.912225 2019] [mpm_prefork:notice] [pid 504] AH00163: Apache/2.4.33 (Unix) PHP/7.1.16 mod_perl/2.0.9 Perl/v5.18.2 configured -- resuming normal operations
[Tue Dec 10 11:02:01.912331 2019] [core:notice] [pid 504] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
这是我在/etc/apache2/users 中的配置文件
<Directory "/Users/nikitakirenkov/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
PerlHandler ModPerl::Registry
Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride None
Require host localhost
</Directory>
PHP 脚本运行良好
如果您真的想使用 mod_perl,并且模块已经加载,那么这对我有用。我使用别名perl-bin来mod_perl脚本。
- File/etc/apache2/conf-available
'
PerlModule ModPerl::Registry
PerlModule Apache::DBI;
PerlModule Apache2::compat;
PerlPostConfigRequire /etc/apache2/startup.pl
ScriptAlias /perl-bin/ /usr/lib/perl-bin/
<Directory "/usr/lib/perl-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Require ip 127.0.0.1 192.168.0.0/16
</Directory>
'
启用配置: `
a2enconf perl
'
File/etc/apache2/startup.pl
1;
使用/etc/lib/perl-bin 中的脚本测试 mod_perl
打开网页并按 F5 几次,然后计数应该会增加。
'
#!/usr/bin/perl
use strict;
use vars qw($count);
use utf8;
my $mod_perl_in_use = $ENV{MOD_PERL_API_VERSION};
print "<h1>Count test </h1>";
print "<b>Mod_perl test script</b><br><br>n";
$count++;
print "The following count will start at 1 and will increment by 1 on each refresh n";
print "(If this was a non-mod_perl script, the counter would always be 1).<br>n";
print "count = $countn<br><br>";
print "pid = $$n<br><br>";
if ($ENV{'MOD_PERL'}) {
print "Mod_perl is installed on this server: $ENV{'MOD_PERL'}<br><br>n";
} else {
print "Mod_perl is not installed on this server<br><br>n";
}
print "<b>Environment variables</b><br>n";
foreach my $key (sort keys %ENV)
{
print ""$key" = "$ENV{$key}"<BR>n";
}
'