Perl CGI error

This is a very simple Perl script.

URL

https://edge.a1z.us/cgi-bin/edge.edge.cgi

Here is the source:

#!/usr/bin/perl

print "Content-Type: text/html\n\n";
print "Edge.Edge\n";


Error:

[Sat Jun 06 15:47:15.259790 2020] [cgid:error] [pid 9326:tid 139686729721600] [client 162.*:63763] End of script output before headers: edge.edge.cgi

Works on CMDLINE

[edge@edge cgi-bin]$ ./edge.edge.cgi
Content-Type: text/html

Edge.Edge
[edge@edge cgi-bin]$

but not on browser

some more details

[edge@edge cgi-bin]$ perl -v

This is perl 5, version 26, subversion 3 (v5.26.3) built for x86_64-linux-thread-multi
(with 51 registered patches, see perl -V for more detail)

Copyright 1987-2018, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[edge@edge cgi-bin]$ uname -a
Linux edge.a1z.us 4.18.0-147.8.1.el8_1.x86_64 #1 SMP Thu Apr 9 13:49:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[edge@edge cgi-bin]$

[edge@edge cgi-bin]$ file /usr/bin/perl
/usr/bin/perl: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=7c8590186d4c0265b355cd02c291b129879680f8, stripped
[edge@edge cgi-bin]$
Status: 
Active

Comments

Is the script owned by the domain owner, and not world-writable?

bislinks's picture
Submitted by bislinks on Sat, 06/06/2020 - 14:11 Pro Licensee

it is 755

bislinks's picture
Submitted by bislinks on Sat, 06/06/2020 - 14:13 Pro Licensee

[edge@edge cgi-bin]$ stat edge.edge.cgi
  File: edge.edge.cgi
  Size: 76              Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d      Inode: 17861391    Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1001/    edge)   Gid: ( 1002/    edge)
Access: 2020-06-06 15:47:15.243546025 +0000
Modify: 2020-06-06 15:46:47.000000000 +0000
Change: 2020-06-06 15:47:03.266484352 +0000
 Birth: -
[edge@edge cgi-bin]$
bislinks's picture
Submitted by bislinks on Sat, 06/06/2020 - 14:35 Pro Licensee

But Perl/Hypnotoad/Mojolicious works.

mojo generate

[edge@edge ~]$ mojo generate app Edge
  [mkdir] /home/edge/edge/script
  [write] /home/edge/edge/script/edge
  [chmod] /home/edge/edge/script/edge 744
  [mkdir] /home/edge/edge/lib
  [write] /home/edge/edge/lib/Edge.pm
  [exist] /home/edge/edge
  [write] /home/edge/edge/edge.conf
  [mkdir] /home/edge/edge/lib/Edge/Controller
  [write] /home/edge/edge/lib/Edge/Controller/Example.pm
  [mkdir] /home/edge/edge/t
  [write] /home/edge/edge/t/basic.t
  [mkdir] /home/edge/edge/public
  [write] /home/edge/edge/public/index.html
  [mkdir] /home/edge/edge/templates/layouts
  [write] /home/edge/edge/templates/layouts/default.html.ep
  [mkdir] /home/edge/edge/templates/example
  [write] /home/edge/edge/templates/example/welcome.html.ep
[edge@edge ~]$

edge.conf

[edge@edge edge]$ cat edge.conf
{
        secrets => ['812*'],
        hypnotoad => { listen => ['http://*:5000'] }
}
[edge@edge edge]$

hypnotoad

[edge@edge edge]$ hypnotoad script/edge
[2020-06-06 19:26:42.19212] [1760] [info] Listening at "http://*:5000"
Server available at http://127.0.0.1:5000
[edge@edge edge]$

URL:

http://edge.a1z.us:5000/

Also check the log file /var/log/httpd/suexec_log, if it exists.

bislinks's picture
Submitted by bislinks on Sat, 06/06/2020 - 20:38 Pro Licensee

suexec_log does not exist

Ilia's picture
Submitted by Ilia on Sun, 06/07/2020 - 06:08

It will not be possible to run scripts like that, as by default, SuexecUserGroup is defined but suexec is pre-compiled, hardcoded path points to /var/www.

There is a work-around though, which I thought would work theoretically, as of now, I tested it practically and here is how it can be done:

  1. Alter in Apache config, the default /var/www/html to something more logical, like /var/www/default and create this directory under /home:
    sed -i 's/\/var\/www\/html/\/var\/www\/default/g' /etc/httpd/conf/httpd.conf
    mkdir /home/default


  1. Mount bind /home to /var/www to trick rigid suexec on RHEL:
     mount -o bind /home /var/www


  1. Edit and change current <VirtualHost> directives' values from /home to /var/www

  2. Restart Apache by running systemctl restart httpd command.

Enjoy running scripts (other than PHP), as server owner, without re-building Apache.

Jamie, do you think we could do it on Virtualmin side automatically? :--)

bislinks's picture
Submitted by bislinks on Thu, 07/16/2020 - 09:00 Pro Licensee

Thanks Ilia. I know it has been a while since you answered this question .. but i tried it today ... it worked.

bislinks's picture
Submitted by bislinks on Thu, 07/16/2020 - 12:50 Pro Licensee

Answer to your question: If you reload the left menu, do you see all domain names listed as expected?

Yes. List Virtual Domains lists all domains on the machine.

Also, recheck config did not show any errors.