Question : (2)No such file or directory: exec of '/var/www/cgi-bin/index.cgi' failed

Hello I am a newbie to perl-cgi. I am trying to run the hello world cgi script but Apache keeps giving me "500 Internal Server Error". So I checked my apache error log to see what the issue was, and I get this "(2)No such file or directory: exec of '/var/www/cgi-bin/index.cgi' failed" error, and below that another log mentions "Premature end of script headers: index.cgi". I tried to see if the shibang line was wrong and went back to test the perl script, and it worked fine. I also double checked the perl path by doing "which perl" and my shibang line was right. I am adding the code snippet that I am using, could anyone tell me what could the problem be, and a possible solution.

I am using a ubuntu as my OS. I have assigned webserver as the owner of the cgi-bin folder and also have set executable file permissions, by using chmod 755.
1:
2:
3:
4:
#!usr/bin/perl

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

Answer : (2)No such file or directory: exec of '/var/www/cgi-bin/index.cgi' failed

It may be helpful to check your httpd.conf file - /etc/httpd/conf/httpd.conf. I'm going to guess this is NOT the problem, because this is standard configuration. But you need to be sure. First look for DocumentRoot. It should be
DocumentRoot "/var/www"

Then look for ScriptAlias. It should be
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

Personally, I like seeing just /cgi/index.cgi in the browser address bar, so I have
ScriptAlias /cgi/ "/var/www/cgi-bin/"

It's not necessary, but if you want www.yoursite.com/cgi-bin to load index.cgi then you should include index.cgi on the DirectoryIndex line
DirectoryIndex index.html index.htm index.cgi index.php

I included index.php because I see you have the php module enabled, so it might as well be there in case you run any php applications.

And, as svqmuc says, be sure this is there
<Files ~ "\.cgi$|\.pl$">
        SetHandler cgi-script
</Files>
which tells Apache that files ending in .cgi or .pl are cgi-scripts. You can remove
|\.pl$
if you don't ever save your Perl scripts with that extension.


Random Solutions  
 
programming4us programming4us