Panix, New York's first
Internet Service Provider


How To Troubleshoot Your CGI Scripts



If you try to use a CGI script on your web page and you get an Internal Server Error. Please go through the following steps to troubleshoot the problem.

NB: It is important to keep track of system upgrades; a major upgrade can cause programs to stop working.

Upgrades are announced well in advance, via MOTDs and in panix.upgrades. We urge everyone to keep track of those announcements and to do thorough testing in the new environment.


STEP 1: Check Permissions and Group Ownership

The Apache Server software that we run on our web servers has certain group ownership and permissions requirments for CGI scripts. For more information about permissions in UNIX and how to change them see the man page for the chmod command. Please check to see that your script meets the following requirments:

  1. The directory the CGI script resides in must not be writable by other or by group users.
  2. The CGI script itself must not be writable by other or by group users.
  3. CGI script must not have the setuid bit set.
  4. You must call SSI execs by their full pathname, for example:
    If you are running a UNIX command located on the web server it would look something like this:
    <!--#exec cmd="/usr/bin/date"-->
    
    If you are running a script that is in your pcgi-bin it might look something like this for corp-web customers:
    <!--#exec cmd="/htdocs/youruserid/pcgi-bin/bar.pl"-->
    
    and like this for cheap-web and personal web customers:
    <!--#exec cmd="/htdocs/userdirs/youruserid/pcgi-bin/bar.pl"-->
    
  5. The target userid may not be < 100 and the target gid may not be < 20. This rule only affects staffers' CGI scripts. Staffers must chgrp their scripts to group users or some other group.
  6. The minimum permissions for CGI scripts is mode 500 and for CGI compiled prgrams, mode 100. You can of course grant more permisson if you wish. For more information about permissions and how to change them see the man page for the chmod command.
  7. The minimum permissions for server-parsed-html (.shtml) files is mode 004 (readable by other), and exec files included therein must be at least mode 700 for scripts and 500 for binaries. For more information about permissions and how to change them see the man page for the chmod command.

STEP 2: Check Your httpd Logs

Personal Web Pages
Corporate Web Pages

How to read error logs for Personal Web Pages


If you have a telnet client installed and your web browser is properly configured, you can use the telnet links below to login to your panix user machine. Then follow these instructions:

  1. If you use the Panix menu, type ! to get to a UNIX shell prompt.
    Type
           agrep $USER /net/local/lib/httpd/httpd_logs/userdirs/error_log.www* | tail 
  2. The cursor may blink for a few minutes and then it will show you the last few errors that occured.
  3. The error message should give you some idea of what is going wrong. If it says "Premature End of Script Headers" or if there doesn't seem to be any error message for the script you are troubleshooting please go to STEP 3 below.

Telnet to panix
Telnet to panix2
Telnet to panix3

How to read error logs for Corporate Web Pages

If you have a telnet client installed and your web browser is properly configured, you can use the telnet links below to log in to your panix user machine. Once you've logged in, follow these instructions:

  1. Your httpd logs are located in a sub-directory of your corp-web directory.
  2. If you use the Panix menu, type ! to get to a UNIX shell prompt.
    Type
           cd corp-web/httpd_logs 
  3. Then type
    tail error_log
    
  4. This will show you the last few errors that occurred.
  5. The error message should give you some idea of what is going wrong. If it says "Premature End of Script Headers" or if there doesn't seem to be any error message for the script you are troubleshooting please to to STEP 3 below.

Telnet to panix
Telnet to panix2
Telnet to panix3

STEP 3: Check Your cgi-log

Personal Web Pages
Corporate Web Pages

How to Read Your cgi-log for Personal Web Pages

If you have a telnet client installed and your web browser is properly configured, you can use the telnet links below to login to your panix user machine. Then follow these instructions:
  1. If you use the Panix menu, type ! to get to a UNIX shell prompt.
    Type
           
    cd /net/local/lib/httpd/httpd_logs/userdirs 
    
  2. Then type
     grep program name cgi-log.www* 
    (Put the name of the program you are troubleshooting in place of program name above.)
  3. This will show you the last few log entries.
  4. If the log entry looks something like this:
    [19:19:55 26-03-97]: uid: (13215/13215) gid: (99/99) new-orderform.cgi
    
    it means that your program ran but it must be exiting for some reason. Try putting
    print ("Content-type:text/plain\n\n");
    
    at the very beginning of your script, this will let you see any error messages that are currently disappearing in to the void. If you get a blank page instead of an error message, add a whole pile of print statements to try to see how far it gets and where it is dying.
  5. If the log entry does not look like the one above then it means that the program did not run and it will tell you why. Usually it is a permissions or group ownership problem (see STEP 1 above).

Telnet to panix
Telnet to panix2
Telnet to panix3

How to Read Your cgi-log for Corporate Web Pages

If you have a telnet client installed and your web browser is properly configured, you can use the telnet links below to login to your panix user machine. Then follow these instructions:
  1. Locate the web server that has your files.

    If you use the Panix menu, type ! to get to a UNIX shell prompt.

    Type the following:

    telnet www.domain-name

    Replace domain-name above with your domain name
    For example, if your domain name is smith.com then you would type www.smith.com

    You will see output that looks something like this:

    Trying 166.84.58.136...
    Connected to www.dube.com.
    Escape character is '^]'.
    
    / (web6.panix.com) (ttyp0)
    
    login:
    

    The name of your webserver is found on the second to last line. In this example the web server is web6.

    In order to exit this screen please type

    CNTL-D

    This means hold down the 'Control' key on your keyboard while pressing the letter 'd'. You do not need to hold down the shift key as well, the 'D' in 'CNTL-D' is capital by convention only. You will be returned to a UNIX prompt.

  2. Once you know the name of your webserver, at the UNIX prompt type
           cd /net/local/lib/httpd/httpd_logs/corp-dirs 

    Then type
           agrep program name cgi-log.webn | tail

    (Put the name of the program you are troubleshooting in place of program name above and change webn to the name of your web server.)
  3. This will show you the last few log entries.
  4. If the log entry looks something like this:
    [19:19:55 26-03-97]: uid: (13215/13215) gid: (99/99) new-orderform.cgi
    
    it means that your program ran but it must be exiting for some reason. Try putting
    print ("Content-type:text/plain\n\n");
    
    at the very beginning of your script, this will let you see any error messages that are currently disappearing in to the void. If you get a blank page instead of an error message, add a whole pile of print statements to try to see how far it gets and where it is dying.
  5. If the log entry does not look like the one above then it means that the program did not run and it will tell you why. Usually it is a permissions or group ownership problem (see STEP 1 above).

Telnet to panix
Telnet to panix2
Telnet to panix3

STEP 4: It Still Doesn't Work, What Do I Do Now?

If you have tried all of these things and you are still having a problem try posting to the newsgroup panix.user.html There are many panix users and staff members who frequent that group who can help you figure out what is wrong. Please post as much information as you can about the script and any troubleshooting measures you have already taken.

Return to Index

Last Modified Thursday, 01-Feb-2007 17:43:34 EST