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

    Joined:
    May 27, 2011
    Location:
    New Zealand
    #1
    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.
     
  2. larkost macrumors 6502a

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

    Jim bob 2011

    Joined:
    May 27, 2011
    Location:
    New Zealand
    #3
    thanks

    Yes just needed to use unix line endings.

    have also changed httpd.conf settings.

    Thanks for your help.! :D
     

Share This Page