We help IT Professionals succeed at work.

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

gautam_reddyc
gautam_reddyc used Ask the Experts™
on
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.
#!usr/bin/perl

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

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The cgi handler doesn't call the perl binary. Instead, it uses an apache module that might be missing in your setup. Please check if you have mod-perl installed and if you have apache configured to use mod-perl.

Author

Commented:
how would I check that svgmuc??

Commented:
Running httpd -M should show a list of loaded modules.
You may need to specify the path of httpd.

Author

Commented:
I have installed mod-perl2 library for apache, but it doesn't list under the enabled modules. How do I enable it??

Author

Commented:
Loaded Modules:
 core_module (static)
 log_config_module (static)
 logio_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 alias_module (shared)
 auth_basic_module (shared)
 authn_file_module (shared)
 authz_default_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 perl_module (shared)
 php5_module (shared)
 setenvif_module (shared)
 status_module (shared)
Syntax OK


These are the modules loaded when I do a apache2ctl -M. I find the cgi module is included, should this be it or should it be different for mod-perl2?

Commented:
You have the perl_module... that should be enough.
Do other perl-CGIs work?

If not, you need to check the handler for .cgi files.
Programmer
Commented:
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.


Author

Commented:
works! cgi-bin location was the problem!