0

I copied my printenv.pl file into /usr/lib/cgi-bin and ran:

chmod +rx printenv.pl 

In my apache2.conf file, I added the following lines:

<Files ~ "\.pl$"> Options +ExecCGI </Files> AddHandler cgi-script .pl 

And restarted the Apache server:

/etc/init.d/apache2 start 

But when I go to http://localhost/cgi-bin/printenv.pl I get the following error:

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Apache/2.2.17 (Ubuntu) Server at localhost Port 80 

Here's my error log file:

[Thu Jul 28 19:28:43 2011] [error] [client 127.0.0.1] (2)No such file or directory: exec of '/usr/lib/cgi-bin/printenv.pl' failed [Thu Jul 28 19:28:43 2011] [error] [client 127.0.0.1] Premature end of script headers: printenv.pl 

But this is what my /usr/lib/cgi-bin directory looks like:

/usr/lib/cgi-bin$ ls -l total 8 -rwxr-xr-x 1 root root 331 2011-07-28 19:01 printenv.pl -rwxr-xr-x 1 root root 335 2011-07-28 18:50 printenv.pl~ 

Can you please help me fix this... thanks!

4
  • 1
    Can you add the contents of that file to your question? Seems like it's having trouble running it. Commented Aug 12, 2011 at 21:07
  • hi Shane, here's the code: #!usr/bin/perl ## ## printenv -- demo CGI program which just prints its environment ## use CGI qw(:standard escapeHTML); $| = 1; print "Content-type: text/html; charset=iso-8859-1\n\n"; foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"<br>\n"; } Commented Aug 13, 2011 at 3:52
  • Leading slash in interpreter's path is missing, replace #!usr/bin/perl with #!/usr/bin/perl Commented Aug 13, 2011 at 8:10
  • did that, still no difference. is there a series of steps i should follow in a specific order bcoz I could try to do the whole thing all over again Commented Aug 13, 2011 at 14:26

1 Answer 1

1

Double-check the first line of your script.

If the line does not begin with #! or perl is installed in a different location than the path following the #! (e.g., /usr/local/bin/perl vs /usr/bin/perl), you will get that error.

If the path to perl appears correct, and you've copied over the script from a Windows machine, you may be being tripped up by a carriage return character at the end of the line.

You can use cat -v /usr/lib/cgi-bin/printenv.pl | head -1 to verify that there isn't a ^M at the end of the line.

If there is, you can use perl -pi.bak -e 's/\r+$//' /usr/lib/cgi-bin/printenv.pl to remove it.

3
  • hi Kanji, I double checked the path to perl and it is correct. I used the cat function and there isn't a ^M. here's the output of the cat: cat -v /usr/lib/cgi-bin/printenv.pl | head -1 #!usr/bin/perl Commented Aug 13, 2011 at 3:35
  • 1
    Is that a straight cut and paste? If so, you are missing a / before usr. If it isn't, are you able to run the script directly from the shell? Commented Aug 13, 2011 at 4:09
  • yes indeed, I ran it from the shell and it executes fine, here's the beginning of the output from that : Content-type: text/html; charset=iso-8859-1 COLORTERM="gnome-terminal"<br> COMPIZ_CONFIG_PROFILE="ubuntu"<br> DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-WtKdwSEdHu,guid=49985f2d6dfd6826a291778300000015"<br> DEFAULTS_PATH="/usr/share/gconf/gnome.default.path"<br> DESKTOP_SESSION="gnome"<br> DISPLAY=":0"<br> Commented Aug 13, 2011 at 4:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.