Fixing a 500 Server Error
Problem
Your CGI script gives you a 500
Server
Error
.
Solution
Follow the checklist given in the discussion. It’s aimed at a Unix audience, but the general principles embodied in the questions apply to all systems.
Discussion
Make sure the web server can run the script.
Check ownership and permissions with ls -l. The appropriate read and execute bits must be set on the script before the web server can run it. The script should be readable and executable by everyone (or at least by whomever the server runs scripts as). Use chmod 0755 scriptname if it’s owned by you, otherwise chmod 0555 scriptname if owned by the designated anonymous web user, assuming you are running as that user or the superuser. All directories in the path must also have their execute bit set.
Make sure the script can be identified as a script by the web server.
Most web servers have a system-wide cgi-bin
, and
all files in that directory will be run as scripts. Some servers
identify a CGI script as any file whose name ends in a particular
extension, like .cgi
or
.plx
. Some servers have options to permit access
via the GET method alone, and not through the POST method that your
form likely uses. Consult your web server documentation,
configuration files, webmaster, and (if all else fails) technical
support.
If you’re running on Unix, do you have the right path to the
Perl executable on the #!
line? The
#!
line must be the first line in the script; you can’t even have blank lines before the ...
Get Perl Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.