Apache (2) throws "No such file or directory: exec of '/usr/lib/cgi-bin/fst.cgi' failed"

Manju picture Manju · Oct 22, 2011 · Viewed 36.5k times · Source

I am working in Ubuntu 10.10 (Maverick Meerkat) and running my CGI script under Apache, but it is showing me the following error...

[Sat errorNo such file or directory: exec of '/usr/lib/cgi-bin/fst.cgi' failed [Sat Oct 22 02:56:45 2011] [error] [client 127.0.0.1] Premature end of script headers: fst.cgi

My script is

#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "hello world";

I have set the permissions of the file...

I have also added the following line in file apache.conf:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

<Directory /usr/lib/cgi-bin/>
   Options +ExecCGI
</Directory>

AddHandler cgi-script .cgi .pl

But still it is showing me the same error. I have done all the possible changes, but I didn't get any success...

Answer

Sam Tseng picture Sam Tseng · Dec 25, 2011

I encountered the same error found in my /var/log/apache2/error_log. I finally realized that the Perl script was directly copied from my Windows system (via Parallels virtual machine) and it seems that the Windows' carriage return "\r\n" causes this error.

When I FTP this Perl script from Windows to Mac using ASCII mode to automatically convert "\r\n" into "\r", the same Perl script works correctly without any modification.