Not running CGI's

Discussion in 'Apache' started by GAP GAP, Feb 28, 2013.

  1. #1
    Hi,

    I'm not an admin, but since we don't have one here I need to do this by myself. Right now main issue is that I can't make apache run cgi's, I have followed several documents in different pages without luck, I can run normal html pages but not cgi's. I only get the code displayed in screen.

    Is there any checklist that I can follow to see if I'm missing something?

    TIA
    Gap
     
    Last edited by a moderator: Feb 28, 2013
    GAP GAP, Feb 28, 2013 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    1. Check if you have perl installed on your server. You can achieve this by typing "perl -v" while being logged in via SSH on your server. If it spits out any perl version then it is installed. Anything else would mean that you need to install perl first (this procedure may be different depending on the type of the server you are running eg windows or linux)
    2. If you are using linux and apache, then check httpd.conf file (you can use "locate httpd.conf" via SSH to find the proper one), and check for following things:
    • Look for a line that says "ServerName yourdomain.com" it should be right after the line that starts like this "<VirtualHost ..." and between those <VirtualHost ...> and closed </VirtualHost> check if you have the line that says "ScriptAlias /cgi-bin/ /home/yoursiteusername/public_html/cgi-bin/"
    • Check if your httpd.conf contains a line that mentions cgi-script anywhere. The line should look something like this: "AddHandler cgi-script .cgi .pl" or perhaps "AddHandler cgi-script .cgi .pl .plx .ppl .perl"
    • Check if your httpd.conf mentions anywhere ExecCGI. the line should look something like this: "Options +ExecCGI" (and may have some other directives there as well, so just make sure you have ExecCGI and don't delete other if any listed there as well after ExecCGI)
    Hmmm I'm not sure if I missed something here... but that should be the most important stuff to check. After that just check few basic things when trying to run cgi script:
    1. Make sure your cgi-bin folder is chmod-ed to 755
    2. Make sure your cgi script is uploaded via ascii/txt mode, and never via binary mode
    3. Make sure your script is chmod-ed to 755
    4. Try some basic script for your first attempt, for example:
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    print "<H1>Hello World</H1>\n";
    Code (markup):
    Note here that perl path may be different on your server, so make sure your perl is actually located at /usr/bin/perl (for example when in SSH try running "/usr/bin/perl -v")

    Additionally if the script doesn't work in your browser, try testing it via SSH and run "perl yourscript.cgi" (or yourscript.pl, or whatever you name it) and test it that way if it works on the system at all, regardless of apache settings.
     
    pr0t0n, Mar 1, 2013 IP