⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch19_04.htm

📁 By Tom Christiansen and Nathan Torkington ISBN 1-56592-243-3 First Edition, published August 1998
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<HTML><HEAD><TITLE>Recipe 19.3. Fixing a 500 Server Error (Perl Cookbook)</TITLE><METANAME="DC.title"CONTENT="Perl Cookbook"><METANAME="DC.creator"CONTENT="Tom Christiansen &amp; Nathan Torkington"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1999-07-02T01:45:21Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-243-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch19_01.htm"TITLE="19. CGI Programming"><LINKREL="prev"HREF="ch19_03.htm"TITLE="19.2. Redirecting Error Messages"><LINKREL="next"HREF="ch19_05.htm"TITLE="19.4. Writing a Safe CGI Program"></HEAD><BODYBGCOLOR="#FFFFFF"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl Cookbook"><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><p><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch19_03.htm"TITLE="19.2. Redirecting Error Messages"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 19.2. Redirecting Error Messages"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1"><ACLASS="chapter"REL="up"HREF="ch19_01.htm"TITLE="19. CGI Programming"></A></FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch19_05.htm"TITLE="19.4. Writing a Safe CGI Program"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 19.4. Writing a Safe CGI Program"BORDER="0"></A></TD></TR></TABLE></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="ch19-12002">19.3. Fixing a 500 Server Error</A></H2><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-pgfId-324">Problem<ACLASS="indexterm"NAME="ch19-idx-1000005400-0"></A><ACLASS="indexterm"NAME="ch19-idx-1000005400-1"></A><ACLASS="indexterm"NAME="ch19-idx-1000005400-2"></A><ACLASS="indexterm"NAME="ch19-idx-1000005400-3"></A></A></H3><PCLASS="para">Your CGI script gives you a <CODECLASS="literal">500</CODE> <CODECLASS="literal">Server</CODE> <CODECLASS="literal">Error</CODE>.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-pgfId-330">Solution</A></H3><PCLASS="para">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.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch19-pgfId-336">Discussion</A></H3><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="ch19-pgfId-1000005146">Make sure the web server can run the script.</A></H4><PCLASS="para">Check ownership and permissions with <EMCLASS="emphasis">ls -l</EM>. 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 <EMCLASS="emphasis">chmod 0755 scriptname</EM> if it's owned by you, otherwise <EMCLASS="emphasis">chmod 0555 scriptname</EM> 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.</P><PCLASS="para">Make sure the script can be identified as a script by the web server. Most web servers have a system-wide <ICLASS="filename">cgi-bin</I>, 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 <ICLASS="filename">.cgi</I> or <ICLASS="filename">.plx</I>. 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.</P><PCLASS="para">If you're running on Unix, do you have the right path to the Perl executable on the <CODECLASS="literal">#!</CODE> line? The <CODECLASS="literal">#!</CODE> line must be the first line in the script; you can't even have blank lines before the <CODECLASS="literal">#!</CODE> line. Some operating systems have ridiculously short limits on the number of characters that can be in this line, so you may need to make a link (e.g., from<ICLASS="filename"> /home/richh/perl</I> to<ICLASS="filename"> /opt/installed/third-party/software/perl-5.004/bin/perl</I>, to pick a hypothetical pathological example).</P><PCLASS="para">If you're running on Win32, have you associated your Perl scripts with the correct Perl executable?</P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="ch19-pgfId-1000005160">Make sure the script has permissions to do what it's trying to do.</A></H4><PCLASS="para">Identify the user the script runs as by replacing with the simple code shown in <ACLASS="xref"HREF="ch19_04.htm#ch19-11169"TITLE="webwhoami">Example 19.2</A>.</P><DIVCLASS="example"><H4CLASS="example"><ACLASS="title"NAME="ch19-11169">Example 19.2: webwhoami</A></H4><PRECLASS="programlisting">#!/usr/bin/perl# webwhoami - show web users idprint &quot;Content-Type: text/plain\n\n&quot;;print &quot;Running as &quot;, scalar getpwuid($&gt;), &quot;\n&quot;;</PRE></DIV><PCLASS="para">This prints the username the script is running as.</P><PCLASS="para">Identify the resources the script is trying to access. List the files, network connections, system calls, and so on, which require special privilege. Then make sure they can be accessed by the user the script is running as. Are there disk or network quotas? Do the protections on the file allow access? Are you trying to get to the encrypted password field using <CODECLASS="literal">getpwent</CODE> on a shadow password system (since usually only the superuser can get shadow passwords)?</P><PCLASS="para">Set permissions on any files the script needs to write to at <CODECLASS="literal">0666</CODE>, or better yet to <CODECLASS="literal">0644</CODE> if they're owned up the effective user ID the script is running under. If new files are to be created or old ones moved or removed, write and execute permission on enclosing directory of those files is also needed.</P></DIV><DIVCLASS="sect3"><H4CLASS="sect3"><ACLASS="title"NAME="ch19-pgfId-1000005175">Is the script valid Perl?</A></H4><PCLASS="para">Try to run it from a shell prompt. CGI.pm lets you run and debug your scripts from the command line or from standard input. Here, <CODECLASS="literal">^D</CODE> represents whatever you type to get an End of File.</P><PRECLASS="programlisting">% perl -wc cgi-script        # just compilation% perl -w  cgi-script        # parms from stdin<CODECLASS="userinput"><B><CODECLASS="replaceable"><I>(offline mode: enter name=value pairs on standard input)</I></CODE></B></CODE><CODECLASS="userinput"><B><CODECLASS="replaceable"><I>name=joe</I></CODE></B></CODE><CODECLASS="userinput"><B><CODE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -