Error 500 "Internal Server Error"


Error 500 "Internal Server Error" occurs if it is impossible to run the script that you have placed on the server, in case of errors in the script, as well as in the case when an incorrect instruction is placed in the file.htaccess. This list of reasons for the occurrence of error 500 is not finite, there are still a lot of reasons why error 500 may occur. However, these three cases are the most common.


Let's first consider the case when you put an incorrect instruction in a file.htaccess. If you made a mistake in writing the name of the necessary directive or parameters to it, you will find something like this error in the error.log file:


[Wed Apr 14 17:01:38 2004] [alert] [client 217.16.16.16]
/home/uXXXXX/aaa.ru/www/.htaccess:Invalid command 'DrectoryIndex',
perhaps mis-spelled or defined bya module not included in the server
configuration

The web server will tell you which specific directive it considered erroneous - it will need to be corrected. In this case, the web server reported that it does not know the DrectoryIndex directives. And indeed — there is no directive DrectoryIndex, there is DirectoryIndex. There is a typo.


If error 500 occurs when accessing a Perl script located in the cgi-bin directory, you need to check the access rights to this script. The rights must be 755 (rwxrx-rx). If this is not the case, you need to change the rights to 755 with the command chmod 755 script.pl in unix shell or use FTP for this. It should be noted separately — the rights to scripts must be set strictly in 755.


Please check if you used the correct FTP file transfer mode when uploading the script to our server. All scripts, as well as any other text files, must be transmitted via FTP in text (ASCII) mode. If the Binary file transfer mode was used, the scripts probably won't work.


If the error has not disappeared after checking the correctness of the installed rights to the script file, you need to examine the latest entries in the error.log file — the web server puts all error messages in it. So you will find a line of the form


[Fri Apr  9 15:05:31 2004] [error][client 217.16.16.16] Premature end of
script headers: /home/uXXXX/aaa.ru/cgi-bin/script.pl

The first thing to do when receiving such an error is to check whether the script correctly issues HTTP headers. Each script must first print a line indicating the corresponding Content-type and only then directly what the user will see (for example, HTML code). Example of a line for issuing the header of a regular HTML document:


print "Content-type: text/html; charset=windows-1251nn";

If the error 500 has not disappeared even after issuing the correct headers, you need to check the correctness of the script as a whole. To do this, you need to get access to the unix shell and then run the syntax check command:


> perl -cw script.pl
script.pl syntax OK

If the script is written with errors, they need to be corrected, guided by the appropriate diagnostics, and also check the syntax of the script again.