I'm having this same problem on a Pi 2 running the latest raspbian. I haven't mucked around with either Perl or the Apache2 install so I'm not sure why this isn't working right out of the box.
When I run this simple script:
Code: Select all
#!/usr/bin/perl
#
#############################################################
# We use these fine modules...
use strict;
use warnings;
use CGI;
use CGI::Carp('fatalsToBrowser');
#use HTML::Template;
#############################################################
# Create a new CGI Object for the form input
my $Q = new CGI;
print $Q->header;
print $Q->start_html;
print "Hi Bill";
print $Q->end_html;
I get this error message (perl's least helpful message):
Code: Select all
[Mon Apr 27 12:05:03 2015] [error] (8)Exec format error: exec of '/usr/lib/cgi-bin/ezInvoice4/test.cgi' failed
[Mon Apr 27 12:05:03 2015] [error] [client 192.168.0.86] Premature end of script headers: test.cgi
When run the script from the terminal I get this:
Code: Select all
pi@pi /usr/lib/cgi-bin/ezInvoice4 $ perl test.cgi
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
Hi Bill
</body>
</html>pi@pi /usr/lib/cgi-bin/ezInvoice4 $
In the "etc/apache2/sites-available/default" file is this:
Code: Select all
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And these are the permissions for the cgi-bin ( changed them to 777 while debugging this.):
Code: Select all
pi@pi /usr/lib $ ls -l
total 91812
drwxr-xr-x 7 root root 4096 Mar 7 10:38 apache2
...
drwxrwxrwx 3 root root 4096 Apr 26 19:53 cgi-bin
I figured I might need to set the filename extension for cgi scripts to ".cgi" so I added this "AddHandler cgi-script .cgi" line to the "/etc/apache2/sites-available/default" file:
Code: Select all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script .cgi
Order allow,deny
Allow from all
</Directory>
But that still didn't work.
I went through the docs at
apache for this but still have this issue.
Whatever the problem, I'd like to solve and document the solution instead of installing nginx or lighttpd. Those are great, but I run apache on my production server and I'm using it on this Pi for developing other stuff besides perl cgi right now.