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.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
For whatever reason your .pl script is aborting. Apache is attempting to run the program but its crashing. It may be the missing interpreter, or some other error in it. Running the program from the command line may be illuminating as well. –  Josh Budde Jul 14 '10 at 19:57
    
Ugh. Line endings were indeed the problem. That's more than a bit idiotic of Apache... Sigh –  Paul Nathan Jul 14 '10 at 20:29

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.