Debugging internal server errors (premature end of script headers) part 2

Let's start at the very beginning...

If you've installed your script, these are the steps you should have gone through (if not, check them now, this is the first stage of your troubleshooting!!)
  • Make sure you uploaded your files in ASCII mode!!!!
  • Any file with a cgi/pl extension should have permissions (chmod) of 755 or 777.
  • Any file that gets written to by the script should have permissions of 666.
  • Your path to perl needs to be right.
  • Any settings in a config file need to be right, especially server paths.
  • Check your logs!

    Here's where I tell you - check your error logs. I know, I'm not supposed to have told you that - it's what everyone says. A good place to start is to see if the script is dying due to server limitations. Check in the file manager for your website to see if your logs are viewable through there. Check for a 'logs' directory in ftp. Hopefully you've got some somewhere. Check for a line which says 'out of memory', if it's the script you're trying to install, don't bother going any further. You can't fix it, unless you bug your host to lift the memory limits on scripts. Your best bet is to find another script which isn't so heavy on memory. How will you know which ones don't use much memory? You won't. Install it and you will know.

    Of course, you might find a message in your logs which tells you exactly what's wrong with your script. If so, fix it, and don't bother reading any further!If all you can see is 'premature end of script headers' - read on. We're going to try to solve that one.

    Chmod (file permissions)

    For .cgi/.pl extensions:

    Some servers run scripts under permissions of 755, others use 777. In your ftp program, scroll across to the right if you can't see the 'attributes' list for each file. Next to the .cgi or .pl script, it should have something like this:

      for 755: -rwx-r-xr-x
      for 777: -rwxrwxrwx
    If they look like:
      -rw-r--r--
    then they're set wrong. the 'r' is read, the 'w' is write and the 'x' is execute. There's no execute permissions at all above, so nobody can execute the script. I won't go into owner/group/public details here, it's enough to say you should have .cgi or .pl scripts set at one of the first two above.

    For .txt/.db extensions or any files that get written to by the script:

    Files that get written to by the script need to have permissions set so anybody can write to them. The setting for this is 666. How this will look in your ftp program:
      -rw-rw-rw-
    If the permissions aren't set right on the files that get written to, your script will error because it can't write to the file so can't go any further - and will 'die' during the execution of the script.

    So how do you change them?

    Through an ftp program is the easiest. Right click on the file you wish to change permissions for, and choose 'CHMOD' from the dropdown list. A box will pop up, with 'owner permissions', 'group permissions' and 'public permissions'. Your ftp program may be a little different in what it says, but I'm sure you'll work out which is which.

    For chmod 666, you need to set the following permissions:

      owner: read, write.
      group: read, write.
      public: read, write.

    For chmod 755, you need to check the following boxes:

      owner: read, write, execute.
      group: read, execute.
      public: read, execute.

    For chmod 777, you need to set the following permissions:

      owner: read, write, execute.
      group: read, write, execute.
      public: read, write, execute.
    Alternatively, ftp should provide a box where you can type in the number that you wish to set the file at. Type in either 666, 755 or 777, depending on what you're setting the file at. Click ok after you've done either method, and the permissions will then be changed on the file.

    * handy hint: use your ctrl button to select several files at once, and you can chmod them all at the same time

    * another handy hint: some ftp programs aren't set to refresh the list after you've changed something, so it will look like the chmod didn't work. Refresh your list in ftp to see the changed settings (there should be a 'refresh' button somewhere)

    So how do you know whether to set the chmod to 755 or 777? Check any help files where you signed up for your website - a faq, forum, whatever. You may find the information in there somewhere. If not, then it's a case of working it out which we'll try to do on the next page.