Debugging internal server errors (premature end of script headers)

...or, how to rip your hair out with a refresh of a page.

I've been there. You've been there, or you wouldn't be reading this now. You found a you-beaut script which you want for your site so your visitors can sign a guestbook/post in a forum/send you an email. Great, you think - I got this script for free, now all I gotta do is upload it to my site, change a couple of values in the config file, chmod the files, and link to it. You go about these four steps with an excitement usually only seen at Christmas, and you finally reach the final stage of opening your new guestbook/forum/email script to see what it looks like.

You open your browser to your nice new script...

    ...it's loading...
      ...and presto!! Huh???
Surely your nice new script that you just spent ages getting * just * right isn't supposed to say 'Internal Server Error'???

 

So now what?

First you cry. Then you gotta start tearing your hair out. After you've got yourself those little bald patches on the side, with a mop of hair left on top (unless you have 3 hands, then you can tear your hair out on both sides AND the top at the same time) you can start to work on WHY your nice new free script has that 'Internal Server Error' message on it. So, it's off to a few forums you know of, you know the kind - post your question, and hopefully someone will reply with the answer to your prayers:
    I just installed a script, and when I go to it in a browser it says Internal Server Error. Can someone tell me why it's doing this?
You sit - and wait for your saviour. And wait. And wait. Until someone actually replies to your post with 'check your error logs'.

You proceed to the file manager for your website, open your error log, and find:

    Premature end of script headers
(if you didn't have the 3 hands mentioned above, you can now proceed to tear the hair out on the top of your head).

So why isn't someone being really helpful and telling me why it's doing this?

Simple. An Internal Server Error, and Premature end of script headers, is like one of those windows messages - 'this program has performed an illegal operation'. You just click the ok button, and go on from there. You've got no idea what the illegal error is - it could be just about anything. An Internal Server Error is telling you that an error occured somewhere in the execution of the script. There's no way someone can say to you, 'this is how you fix it' unless you provide them with further information.

Hopefully I can point you in the right direction to find the information you need to either get your script going yourself, or so you can provide someone with some information so they can help you. The first most important thing you need to do is make sure that any scripts you upload, get uploaded in ascii mode.

Ascii - ok, so what does that mean?

When you upload files through ftp, you have the choice of uploading them in 'binary' or 'ascii' mode. You'll get some people tell you that it doesn't matter what you upload them as. This is WRONG!! Chances are these people have an ftp program which auto-detects the file type and uploads them in ascii.

Basically, anything that has text that you read should be uploaded in ascii, images and zip files and stuff like that which isn't text gets uploaded in binary mode. As the file is uploading, you should see a record of what it's doing displayed in your ftp program somewhere (a scrolling screen up the top, or at the bottom). This will say something like 'opening ascii mode connection' or 'opening binary mode connection' as it starts uploading.

If you're uploading a .cgi or .pl script and it says binary - then you will corrupt your script! Find the setting somewhere in your ftp program which states what extensions to upload in ascii, or if you need to choose what mode to upload in for each file you upload, choose ascii. Mine is set to 'auto', with .cgi and .pl in the list to upload as ascii. If you have .pm files with your scripts, these are text files that need to be uploaded in ascii too.