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
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.
You are assuming the current directory is set to the directory containing the script.
The
do
reads a file and executes (eval
s) it as Perl code. If that fails, nothing happens (silently). It’s like ignoring aneval
.require
is likedo
but complains if there was a problem (the perldoc entry shows the actual behavior). You shouldrequire
the file so it can tell you that something didn’t happen. Or, at least, check the result ofdo
and send$@
to the error log if there’s a problem.