Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
1  
Can you add the contents of that file to your question? Seems like it's having trouble running it. –  Shane Madden Aug 12 '11 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"; } –  ba-apache Aug 13 '11 at 3:52
    
Leading slash in interpreter's path is missing, replace #!usr/bin/perl with #!/usr/bin/perl –  Vladimir Blaskov Aug 13 '11 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 –  ba-apache Aug 13 '11 at 14:26

1 Answer 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.

share|improve this answer
    
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 –  ba-apache Aug 13 '11 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? –  Kanji Aug 13 '11 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=49985f2d6dfd68‌​26a291778300000015"<br> DEFAULTS_PATH="/usr/share/gconf/gnome.default.path"<br> DESKTOP_SESSION="gnome"<br> DISPLAY=":0"<br> –  ba-apache Aug 13 '11 at 4:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.