Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jim bob 2011

macrumors newbie
Original poster
May 27, 2011
2
0
New Zealand
Hey Everyone. :)

I have recently been learning how to write CGI scripts using PERL. I Have also figured out how to set up Apache on my mac. I am running a slightly older version, (Apache 2.2.11 to be exact.)

while configuring my httpd.conf file i did the following to enable CGI to run from my directory folder:

<Directory />
Options +ExecCGI
AllowOverride None
Order deny,allow
Deny from all
</Directory>

my server seems to be working alright, but now the problem i am having is when i go to run some of my CGI scripts I get the following error:

[error] [client ::1] (2)No such file or directory: exec of '/Library/WebServer/Documents/projectthread/dynamic_form.cgi' failed,

[error] [client ::1] Premature end of script headers: dynamic_form.cgi,

I have been wondering if this is maybe a problem with the CHMOD settings of these files, or the fact that I wrote some of the code on a P.C. (not by choice) Have tried a few things but nothing seems to be working.

If any body could offer any advice it would be much appreciated.

Cheers.
 
The most likely problem is that your line-endings are wrong, so the interpreter does not know that you want to run it as Perl (note: it is not an initialism, so only needs a single capital letter). So the two things you need to make sure of:

1) That the file is saved using "unix" line endings. Not "MacOS" or "Windows". Any decent text editor can do this for you, including all of the free ones. Even on Windows.

2) Your first line must be this:
Code:
#!/usr/bin/perl
anything else (other that perl options) and you will be in trouble.

Once you are past that, then you need to make sure that you are at least doing this:
Code:
print "Content-type: text/plain\n\nA basic example";
That will print out just "A basic example". For something more complicated you probably want to replace "text/plain" with "text/html". That is the "script headers" that it is actually complaining about the lack of.

Last thing: you don't really want to set options in the "/" section, but rather in the "/Library/Documents/WebServer" section.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.