0

I'm attempting to get a perl script up and running on Oracle Linux 8.5.

My Apache server and virtual hosts work with static html.

My test virtual host, fnu, has a very basic perl script named hw.pl in /var/www/fnu:

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World. This is fnu.";

I have a link from index.html to hw.pl, permissions open and owner set to apache:

-rwxrwxrwx. 1 apache apache 89 Jun  4 20:59 hw.pl
lrwxrwxrwx. 1 apache apache  5 Jun  4 20:59 index.html -> hw.pl

Here's the site config in /etc/httpd/conf.d:

<VirtualHost *:80> 
DocumentRoot "/var/www/fnu/"
ServerName fnu.[obscured].net
ServerAlias fnu
ErrorLog /var/log/fnu/error.log
CustomLog /var/log/fnu/request.log combined
<\/VirtualHost>

<Directory "/var/www/fnu">
    Options +ExecCGI +SymLinksIfOwnerMatch
    AddHandler cgi-script .cgi .pl
<\/Directory>

If I point a browser to fnu/hw.pl, I get the result I expect - the script output. If I point the browser to fnu/, I get the contents of the file. So, it's following the link, but it's not running it as a perl script once it gets there. Nothing useful in /var/log/fnu/error.log.

SELinux is set to Permissive.

I appreciate any assistance.

Script output as expected

Script file contents

chicks
  • 3,639
  • 10
  • 26
  • 36
SKaye
  • 1
  • 1

2 Answers2

0

it's reading index.html as an html file.

one way to rectify this is to tell apache to execute .phtml files as perl.

to do this you locate the:

<IfModule dir_module>
     DirectoryIndex index.html index.phtml index.php
</IfModule>

in your httpd configurations and add index.phtml to the DirectoryIndex list as shown above.

then you want to AddHandler cgi-script .phtml and rename your link to index.phtml.

this should work, but it's been many years since i have used cgi in apache.

another way to do this is to use SSI (Server Side Includes) with mod_include. with this you can create an index.html and <!--#include virtual="/path/to/hw.pl" --> OR <!--#exec cmd="hw.pl" -->

i can't remember which is better, but depending on what your script does you can read the documentation and figure out the best method.

walder
  • 51
  • 3
0

Thank you, I got on the trail of another resource and was able to solve this using SetHandler in the config instead of AddHandler. I realize this may be an over-broad solution in some cases but it is doing what I want here.

<Directory "/var/www/fnu">
    SetHandler cgi-script
    Options +ExecCGI +SymLinksIfOwnerMatch
<\/Directory>

The script now runs when I browse to fnu/.

chicks
  • 3,639
  • 10
  • 26
  • 36
SKaye
  • 1
  • 1
  • Thanks for sharing your solution. Note that this will mean you cannot serve any static files from this directory. Everything in there will be treated as a CGI script. You could make `index.pl` to `DirectoryIndex`, symlink that to your script and base your handlers on extensions you will be able to host both in there. – chicks Jun 07 '22 at 00:33