I've attached a patch for this and a few other issues I encountered trying to use Apache::Test on Debian and Ubuntu.
On Thu Oct 20 10:19:39 2016, JROBINSON wrote:
Show quoted text> Hi,
>
> I *think* this is because ubuntu's apache defaults to a conf file
> named "apache2.conf", whereas this code assumes an "httpd.conf" (I see
> that is configured in the produced t/conf/apache_test_config.pm, but
> somewhere/somehow, its not being used when actually trying to launch
> the apache ?
>
> Actual message:
>
> apache2: Could not open configuration file
> /home/jessr/.cpanm/work/1476969529.7174/Apache-Test-
> 1.40/t/apache2.conf: No such file or directory
>
> This goes away if I copy t/conf/httpd.conf to t/apache2.conf then I
> only get to fails with... with: AH00534: apache2: Configuration error:
> No MPM loaded.
>
> This is: Ubuntu 16.04.1 LTS \n \l and .. Apache/2.4.18
>
> Any ideas?
diff -Naur Apache-Test-1.40.orig/lib/Apache/TestConfigParse.pm Apache-Test-1.40/lib/Apache/TestConfigParse.pm
--- Apache-Test-1.40.orig/lib/Apache/TestConfigParse.pm 2016-09-06 12:18:11.000000000 +0000
+++ Apache-Test-1.40/lib/Apache/TestConfigParse.pm 2017-03-04 23:20:40.335455514 +0000
@@ -87,8 +87,10 @@
'user-supplied $base' ],
[ $self->{inherit_config}->{ServerRoot},
'httpd.conf inherited ServerRoot' ],
- [ $self->apxs('PREFIX'),
- 'apxs-derived ServerRoot' ]);
+ [ $self->apxs('PREFIX', 1),
+ 'apxs-derived ServerRoot' ],
+ [ $self->apxs('SYSCONFDIR'),
+ 'apxs-derived ServerRoot based on SYSCONFDIR' ]);
# remove surrounding quotes if any
# e.g. Include "/tmp/foo.html"
@@ -342,7 +344,7 @@
(my $directive, $_) = split /\s+/, $_, 2;
- if ($directive eq "Include") {
+ if ($directive eq "Include" or $directive eq "IncludeOptional") {
foreach my $include (glob($self->server_file_rel2abs($_))) {
$self->inherit_config_file_or_directory($include);
}
@@ -456,13 +458,31 @@
my $httpd = $self->{vars}->{httpd};
return unless $httpd;
+ # to run this on Debian/Ubuntu's default install we need a few
+ # extra env vars, which are setup by apache2ctl - it's not
+ # terribly important that we get these right, we're not trying to
+ # run the server, but we'll get warnings if we're too far off.
+ # Seems harmless to define them for everyone, but we could add a
+ # check here to try to guess if they're needed, perhaps by running
+ # httpd -V and checking the output.
+ $ENV{APACHE_RUN_DIR} = $self->server_file_rel2abs('');
+ $ENV{APACHE_PID_FILE} = $self->server_file_rel2abs('/tmp/apache2.pid');
+ $ENV{APACHE_LOG_DIR} = $self->server_file_rel2abs('/tmp');
+ $ENV{APACHE_LOCK_DIR} = $self->server_file_rel2abs('/var/lock/apache2');
+ $ENV{APACHE_RUN_USER} = getpwuid($<);
+ $ENV{APACHE_RUN_GROUP} = getgrgid($();
+
$httpd = shell_ready($httpd);
my $cmd = "$httpd -V";
my $httpdconf = $self->{vars}->{httpd_conf};
$cmd .= " -f $httpdconf" if $httpdconf;
- my $serverroot = $self->{vars}->{serverroot};
+ # use server_file_rel2abs so we can check a few possible places
+ # Apache might be hiding its prefered ServerRoot. We need to get
+ # this right for Debian/Ubuntu to work since they don't set a
+ # ServerRoot in their file and then do relative includes
+ my $serverroot = $self->server_file_rel2abs('');
$cmd .= " -d $serverroot" if $serverroot;
my $proc = $self->open_cmd($cmd);
diff -Naur Apache-Test-1.40.orig/lib/Apache/TestConfig.pm Apache-Test-1.40/lib/Apache/TestConfig.pm
--- Apache-Test-1.40.orig/lib/Apache/TestConfig.pm 2016-09-06 12:18:11.000000000 +0000
+++ Apache-Test-1.40/lib/Apache/TestConfig.pm 2017-03-04 23:06:58.962892758 +0000
@@ -442,6 +442,13 @@
if ($vars->{conf_dir}) {
$vars->{httpd_conf} ||= catfile $vars->{conf_dir}, 'httpd.conf';
+
+ # recent Debian/Ubuntu distros have started calling their
+ # apache config apache2.conf
+ if (!-e $vars->{httpd_conf} and
+ -e catfile $vars->{conf_dir}, 'apache2.conf') {
+ $vars->{httpd_conf} = catfile $vars->{conf_dir}, 'apache2.conf';
+ }
}
}