0
votes

Hi since other posts about this topic didn't do me much justice ( none of them seem to apply for Ubuntu 13.10, the version of Ubuntu I run), I decided to make another one. After running these lines ( a fellow stackoverflow member suggested running these)..

cd /etc/apache2/mods-enabled 
sudo ln -s ../mods-available/cgi.load .
sudo ln -s ../mods-available/cgid.load .
sudo service apache2 restart

I placed the cgi files ( they are perl ones ) into my Apache2's cgi-bin @ /usr/lib/cgi-bin. When typing localhost/cgi-bin/test.cgi, I got a 500 Internal server error. This is what the Server error log says..

[Fri Nov 22 21:23:29.045785 2013] [cgi:error] [pid 9559] [client 127.0.0.1:47663] AH01215: (8)Exec format error: exec of '/usr/lib/cgi-bin/test.cgi' failed [Fri Nov 22 21:23:29.046720 2013] [cgi:error] [pid 9559] [client 127.0.0.1:47663] End of script output before headers: test.cgi

test.cgi looks like this...

 #!/usr/bin/perl

 print "Content-type: text/html\n\n";
 print <<HTML;
 <html>
 <head>
 <title>A Simple Perl CGI</title>
 </head>
 <body>
 <h1>A Simple Perl CGI</h1>
 <p>Hello World</p>
 </body>
 HTML
 exit; 

Does anyone know what to do when then happens or have any suggestions? Thanks

EDIT:: Oddly enough, I got this cgi file i call test2.cgi to run.

    #!/usr/bin/perl

    use strict;
    use warnings;

    sub main {

        print "Content-type: text/html\n\n";

        print "Hello world\n\n";

        print "What's your favorite food brah?\n";

    }

    main();

But the larger, more advanced cgi files that I need to work on wont run. These ones include stuff being printed out in html tags.

EDIT: Ignore any weird spacing in code. Its just how i copied it into the post.

1
not sure, I got 500 error with both the perl scripts. The apache error I am getting is, File does not exist: /home/leo/public_html/cgi-bin/sys_cpanel, referer: xxx.xxx.xxx.xxx/~leo/cgi-bin/test1.cgi :(Leo Prince

1 Answers

2
votes

Edit: Its not quite clear if there are extra spaces in the original code at the start of each line causing this issue, if not, ignore the rest of this! Thanks Amon

If you try running them from the console, it will help see immediately any errors. In this case...

Can't find string terminator "HTML" anywhere before EOF 

#!/usr/bin/perl    # make sure no space before # and this comment is not here

print "Content-type: text/html\n\n";
print <<HTML;
<html>
....
</body>
HTML 
exit; # Make sure the HTML line before this has nothing either side of it 

Basically, remove the single space before the #!/usr/bin/perl line as Amon points out if it exists, and also the closing HTML line should fix it (There shouldn't be anything surrounding the heredoc terminator, its not obvious there are spaces at the start of each line, but there are).

Sometimes when putting example code on a site, spaces etc may be introduced to help visually. I'm guessing some were introduced here that were copied into the code. Hard to spot!