Trouble setting up CGI scripts on Apache

Discussion in 'macOS' started by Jim bob 2011, May 27, 2011.

  1. Jim bob 2011 macrumors newbie

    Jim bob 2011

    May 27, 2011
    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

    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.

  2. larkost macrumors 6502a

    Oct 13, 2007
    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:
    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:
    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.
  3. Jim bob 2011 thread starter macrumors newbie

    Jim bob 2011

    May 27, 2011
    New Zealand

    Yes just needed to use unix line endings.

    have also changed httpd.conf settings.

    Thanks for your help.! :D

Share This Page