Getting HTTP 500 Internal Server Error with a script

Updated: 05/21/2018 by Computer Hope

Computer errorA 500 internal server error is often encountered because of an error in the script or the server's inability to understand it, and is not an error caused on your end. The error resides solely on the server that hosts the website.

500 error user troubleshooting

Despite the issue being something you can't control or fix directly, there are a few things you can try to rectify the problem from your computer.

  1. Try reloading the web page (press F5) to see if the error can be cleared up.
  2. Try coming back to the web page at a later time. If you're not the webmaster, it's likely that they are working on the problem.
  3. Contact the webmaster by e-mail. Many web pages have a link on it to contact the company (support email) or the server hosted the page.

In any case, just know that you did not cause the error and your computer or Internet connection are not at fault.

500 error webmaster troubleshooting

If you are responsible for the script or page generating this error, below are steps that can be taken to help identify and fix this error with your script.

Script is not set as executable

All scripts uploaded to a server must have execute permissions (e.g., chmod 755 or -rwxr-xr-x). If you are uploading the file through a graphical FTP program such as FileZilla, right-click the file on the Server and click File permissions to see the permissions.

File is not being uploaded as ASCII (Text)

When uploading any Perl or PHP script file you need to make sure that the file is uploaded in ASCII (Text) mode and not Binary mode. If your program is uploading the files and mode is automatically be set, try switching to manual and make sure it is ASCII (Text) mode.

Perl script doesn't have a shebang or content-Type

If you are uploading a Perl script (files ending with .pl or .cgi,) it must have a shebang as the first line and a content-Type line before any print command. Below is what we recommend having at the top of all your Perl script file. Adding the fatalstobrowser line to our script will print any error to the browser window, which helps debug the script if there are errors in it.


use strict;
use CGI::Carp qw( fatalsToBrowser carpout);

print "Content-Type: text/html", "\n\n";

Not uploaded to the correct directory

Make sure the script file is being uploaded to a directory that has executable permissions. In the case of Perl files, we suggest uploading all Perl files to the public_html/cgi-bin/ directory.

Make sure the file is formatted for Linux

If you have created or edit the script file in a Windows editor such as WordPad or Notepad, these editors can end each line with a different character, which will break any script. If you have access to a shell account on the computer you are uploading the script to, run the dos2unix command to convert that file into a file that does not contain invalid characters.

Test the script

Finally, if all the above suggestions have not helped and you continue to experience the issue verify the script has no errors. For users running Perl script run the below command. If you do not have access to a shell account or a computer with Perl, we suggest installing Perl on your computer.

perl -wc

Additional information