I have attached a patch for this issue and a few others I found while
trying to run tests on recent Debian and Ubuntu servers.  Please let me
know if you have any questions.

Part of this patch came from this Debian patch that seemingly hasn't gotten
back into the main distro:

https://sources.debian.net/patches/libapache2-mod-perl2/2.0.9~1624218-2%2Bdeb8u1/030-apxs-no-prefix.patch/

Sam


On Fri, Mar 3, 2017 at 10:59 PM, Sam Tregar <s...@tregar.com> wrote:

> Hello all.  I've been working on getting Apache::Test running on Debian
> and it's not going well.  One problem seems to be that Debian's system
> Apache conf is not named what Apache::Test thinks it should be named
> (apache2.conf vs httpd.conf).
>
> After solving that problem I hit a bigger one - the system apache2.conf
> file shipped with Debian is quite peculiar.  It requires numerous
> environment variables (i.e. APACHE_RUN_DIR, APACHE_USER, etc) which are set
> in apache2ctl.  Worse, it doesn't define a ServerRoot and neither does apxs
> have a value for prefix.
>
> Part of this bug appears in this bug report:
>
> https://rt.cpan.org/Public/Bug/Display.html?id=118445
>
> In short it seems like Apache::Test relies on the system Apache conf being
> fairly vanilla and sane, but the Debian/Ubuntu maintainers have different
> ideas.  I'm not sure what to do here - perhaps package up a very simple
> default config for Debian/Ubuntu and sub that in?
>
> Any help would be appreciated.  I'm happy to work up a patch if I can only
> figure out what needs to change.
>
> Thanks!
>
> Sam
>
>
>
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';
+        }
     }
 }
 

Reply via email to