Problem:
Apache2 refuses to run my CGI scripts, telling me it cannot find the file.
Sample log:
[Wed Jul 14 09:22:19 2010] [error] [client 192.168.111.1] (2)No such file or directory: exec of '/home/pnathan/public_html/ajax.pl' failed
[Wed Jul 14 09:22:19 2010] [error] [client 192.168.111.1] Premature end of script headers: ajax.pl
Points:
ajax.pl is chmod 755. The directory tree it is in is chmod 755. I have another script in the same directory that runs.
LS of ajax.pl:
-rwxr-xr-x 1 pnathan pnathan 534 2010-07-14 09:12 ajax.pl
My Apache2 config file has this block in it:
<Directory /home/pnathan/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
Options +ExecCGI
AddHandler cgi-script .pl .py
</Directory>
I have no idea what's going on.
I'm guessing that the first line of your script has the name of an interpreter that does not exist on your machine.
Now the difference may be as subtle as the fact that if you moved the script from a Windows machine to a UNIX machine that the line ends with a ^M character.
My suggestion is to open the file in 'vi' and see if it says something like "[dos]" at the bottom of your screen. If it does then my guess is correct.
The easiest tool to correct this is dos2unix.