Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

Enable CGI scripts in Debian Apache2

My /etc/apache2/sites-available/default is set up to handle cgi or pl files like this:

 <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options FollowSymLinks +ExecCGI
                #Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
                AddHandler cgi-script .cgi .pl
        </Directory>

/usr/lib/cgi-bin/perltest.pl is set to chmod 755 and contains this:

###Start###

#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there!<br />\nJust testing .<br />\n";

for ($i=0; $i<10; $i++)
{
print $i."<br />";
}

###End###

I try to execute the script via the browser:

http://server/cgi-bin/perltest.pl

I get the error: HTTP 500 page can not be displayed, internal server error.

I followed this guide to set this up: http://www.ubuntugeek.com/how-to-install-apache2-webserver-with-phpcgi-and-perl-support-in-ubuntu-server.html

I know my setup is slightly different.

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of caterham_www
caterham_www
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tintin
Tintin

Check to see what the error is in the Apache error log or add

use CGI::Carp 'fatalsToBrowser';

in your script.

Did you chmod +x the script?
Avatar of itnifl

ASKER

The script has these rights as described in the question: 755 = u=rwx,g=rx,o=rx.

/var/log/apache2/error.log:

[Tue Mar 24 16:17:16 2009] [error] [client 192.168.1.101] (8)Exec format error: exec of '/usr/lib/cgi-bin/perltest.pl' failed
[Tue Mar 24 16:17:16 2009] [error] [client 192.168.1.101] Premature end of script headers: perltest.pl

So I guess there is something wrong with the script. I have not really started reading on creating CGI files with Perl, but wanted to see my Apache server being able to run the scripts anyway. The script was copied from a tutorial page on the net. Anyone see anything wrong with it?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

Yeah, it was. Didnt think it mattered..  thanks...
Avatar of itnifl

ASKER

Thanks!