skip to Main Content

Apache 2.4 has been configured for Server Side Includes and correctly runs any CGI script passed as long as the variables are local. However, we have a few scripts that use a ‘do’ function to pull in variables from a configuration file, like so:

#!/usr/bin/perl
do '../includes/cgi.conf';
print "Content-type: text/htmlnn";
print $hostname

cgi.conf contains the following:

$host = 'none.nowhere.com';

When executed at the command line on the webserver, the variable populates into the output as expected. However, Apache will not print it as expected unless the variable is declared locally in the script.

I am upgrading an application from RHEL6/Apache 2.2 to RHEL7/Apache 2.4 and this configuration worked previously, so I may have missed something in the upgrade to new configuration.

Please excuse any typos in code blocks. Code was not copy pasted and any typos do not exist in the actual code.

3

Answers


  1. Chosen as BEST ANSWER

    My problem was solved by adding read permissions for the apache user to the configuration file. It had execute permissions only from the old server and I had assumed that was all it needed on the new server.


  2. You are assuming the current directory is set to the directory containing the script.

    use FindBin qw( $RealBin );
    
    do "$RealBin/../includes/cgi.conf";
    
    Login or Signup to reply.
  3. The do reads a file and executes (evals) it as Perl code. If that fails, nothing happens (silently). It’s like ignoring an eval.

    require is like do but complains if there was a problem (the perldoc entry shows the actual behavior). You should require the file so it can tell you that something didn’t happen. Or, at least, check the result of do and send $@ to the error log if there’s a problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search