Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

500 Internal Server Error

I have developed a web site that get's this error about 1/3 of the time it is referenced.

500 Internal Server Error

If you do a refresh on the page, it comes up usually on the first refresh, sometimes takes two or 3.

It ONLY happens on the main page. whasocal.org. If you try it, you may get the error too. Or maybe not.

The only thing different about the main page is that there is an animated gif that runs when it loads. Other pages don't have that. The main page (and ALMOST all others) is php.

I'd appreciate any pointers about what might cause this. I'm using 1 & 1, a large commercial web host that I use for a lot of sites.

I'm pretty sure it's an Apache web server.
Avatar of gheist
gheist
Flag of Belgium image

you need to examone apache error log where every 500 error is logged. Most likely it is 30s run timeout for php pages.
Avatar of slyong
slyong

Hi,

There are a few posibilities:

A malformed php cgi script
An invalid directive in an .htaccess or other config file
Limitation imposed by file system and server software (for example php log file size set to 10Mb)
Missing php.ini (or cannot read php.ini file)

It is best that you can give us the apache log on that error.  You should be able to locate the log file in /var/log/httpd/error_logs
Avatar of Richard Korts

ASKER

To all,

I only have ftp access. How do I get to the error logs?
Avatar of arnold
You should check the apache error log as others pointed out.
What is the underlying code you are using, PHP, or is it a static page? You might want to enable debugging within the pages you use to output the error to the browser.
The issue could be that under certain conditions the response you return is incorrect or missing parameters.
The actual reply on the 500 error is

HTTP/1.1 500 Internal Server Error
Date: Fri, 13 May 2011 14:29:53 GMT
Server: Apache
Content-Length: 645
Connection: close
Content-Type: text/html

together with a body of :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   <head>
      <title>Error 500 - Internal server error</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="cache-control" content="no-cache" />
   </head>
   <body style="font-family:arial;">
        <h1 style="color:#0a328c;font-size:1.0em;">Error 500 - Internal server error</h1>
      <p style="font-size:0.8em;">An internal server error has occured!<br/>Please try again later.</p>
   </body>
  </html>

when it works it returns :-

HTTP/1.1 200 OK
Date: Fri, 13 May 2011 14:31:47 GMT
Server: Apache
X-Powered-By: PHP/4.4.9
Transfer-Encoding: chunked
Content-Type: text/html

so it has nothing to do with the page content.

The top level url is http://whasocal.org but the page returned looks like it has been server side processed, so there must be a rule in Apache to map to the home page and I suspect that this has gone wrong.

Can you explain how the top level paged is accessed (and what it is called)?
There is also the possibility that the php script in the page causes an exception. It might be worth while posting that.
It sounds like this is a hosted website.  You should contact the helpdesk of the hosting provider to get information on how to retrieve those logs or otherwise troubleshoot the problem.  There may be some sort of web-based application that will allow you to view the logs.... at this point, with just FTP access, you probably won't be able to get anywhere with it.
One of the problems I've run into, which is horrible to debug, is that PHP can randomly run into a segmentation fault.  It all depends on how PHP was installed/built, along with the architecture of the server what type of database (if any) it is built to use, and so forth.

One thing that may provide some useful information for you is to create a temporary page, and put in:
<?php
phpinfo();\

Open in new window

To BigRat:

The top level page is index.php. It is the ONLY file called index.* at the root. There are a bunch of other index*.php that represent various versions I have used and / or tested.

In the code window is the source php (with the database password & other keys dummied out)
<?
$Host = "localhost";
$User = "123456";
$Password = "password";
$DBName = "d123456";
$Link = mysql_connect ($Host, $User, $Password);
$qryev = "SELECT * from event order by date_time";
$resev = mysql_db_query($DBName, $qryev, $Link);
$nev = mysql_num_rows($resev);
$dtt = date('Y-m-d');
if ($nev >= 2) {
	$bwh = 606;
} else {
	$bwh = 590;
}		
// get announcements
$qrya = "SELECT * from announcements where expdate >= '" . $dtt . "' order by expdate";
$resa = mysql_db_query($DBName, $qrya, $Link);
$na = mysql_num_rows($resa);
// get text for area 4 if no events
$a4 = "ev";
$anleft = $na;
if ($nev == 0) {
	if ($na == 0 ) {
		$a4 = "dt";
	} else {
		$a4 = "an";
		$an = mysql_fetch_array($resa);
		$a4txt = $an['antext'];
		$anleft = $na - 1;
	}
}			
$dt = date('Y') . "-" . date('m') . "-" . date('d');
$title = "Main Page";
$qrymt = "SELECT * from main_page where type = 'M'";
$resmt = mysql_db_query($DBName, $qrymt, $Link);
$mt = mysql_fetch_array($resmt);
// build array of default texts
$dtxa = array();
$dtxu = array();
$qrydt = "SELECT * from main_default_text where active = 'Y'";
$resdt = mysql_db_query($DBName, $qrydt, $Link);
$ndt = mysql_num_rows($resdt);
if ($ndt != 0) {
	for($i = 0; $i < $ndt; $i++) {
		$dtrow = mysql_fetch_row($resdt);
		$dtxa[$i] = $dtrow[1];
		$dtxu[$i] = 0;
	}
}	
// area 4 (if default text)
if ($a4 == "dt") {	
	srand(time());	
	$ix = rand(0, $ndt-1);
	if ($dtxu[$ix] == 0) {
		$a4txt = $dtxa[$ix];
		$dtxu[$ix] = 1;
	} else {
		$fndtxt = false;
		while (! $fndtxt) {
			$ix = rand(0, $ntd-1);
			if ($dtxu[$ix] == 0) {
				$a4txt = $dtxa[$ix];
				$dtxu[$i] = 1;	
				$fndtxt = true;
			}
		}
	}	
}
// text 2
if ($anleft > 0) {
	$an = mysql_fetch_array($resa);
	$text2 = $an['antext'];
	$anleft = $anleft - 1;	
} else {
	srand(time());	
	$ix = rand(0, $ndt-1);
	if ($dtxu[$ix] == 0) {
		$text2 = $dtxa[$ix];
		$dtxu[$ix] = 1;
	} else {
		$fndtxt = false;
		while (! $fndtxt) {
			$ix = rand(0, $ntd-1);
			if ($dtxu[$ix] == 0) {
				$text2 = $dtxa[$ix];
				$dtxu[$i] = 1;	
				$fndtxt = true;
			}
		}
	}	
}		
// size font for $text2
$lt2 = strlen($text2);
if ($lt2 > 300) {
	$ft2 = "pt9";
} else {
	$ft2 = "pt10";
}		
// text 3
if ($anleft > 0) {
	$an = mysql_fetch_array($resa);
	$text3 = $an['antext'];
	$anleft--;	
} else {
	srand(time());	
	$ix = rand(0, $ndt-1);
	if ($dtxu[$ix] == 0) {
		$text3 = $dtxa[$ix];
		$dtxu[$ix] = 1;
	} else {
		$fndtxt = false;
		while (! $fndtxt) {
			$ix = rand(0, $ntd-1);
			if ($dtxu[$ix] == 0) {
				$text3 = $dtxa[$ix];
				$dtxu[$i] = 1;	
				$fndtxt = true;
			}
		}
	}
}
// size font for $text3
$lt3 = strlen($text3);
if ($lt3 > 300) {
	$ft3 = "pt9";
} else {
	$ft3 = "pt10";
}									
include "build_spons_block.php";
?>	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? print $title; ?></title>
<link href="/css/mainr3.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#bodyWrapper1 {
   width: 966px;
   height: <? print $bwh; ?>px;;
   margin-left: auto;
   margin-right: auto;
   background-color: transparent;
}
.li1 { margin-left: -1em } 
div#container {
  width: 800px;
}
div#left {
  width: 350px;
  float: left;
}
div#center {
	width: 343px;
	float: left;
}	
h2.title {
   font-size: 15px;
   color: #011E3C;
   margin-top: -0.5em;
   font-weight: bold;
}

.ltbl {font-size: .8em; font-family: Arial; color: #4E6C8E; }

</style>	
<script language="JavaScript">	
<!--
<? if ($_GET['blog'] == "n") { ?>
	noblog = true;
<? } else { ?>
	noblog = false;
<? } ?>	
<? if ($_GET['sm'] == "1") { ?>
	sm = true;
<? } else { ?>
	sm = false;
<? } ?>			
<? if ($_GET['jm'] == "1") { ?>
	jm = true;
<? } else { ?>
	jm = false;
<? } ?>			
	function chk_msgs() {
		if (noblog) {
			alert("Blog only available to Board Members.");	
		}
		if (sm) {
			alert("Thank you for sending us a message.  We will respond to you soon. ");
		}	
		if (jm) {
			alert("Thank you for joining our mailing list! - WHA");
		}			
		return true;	
	}
// -->
</script>
</head>
<body style="margin-left: 0px;" onload="chk_msgs();">
<!-- DO NOT MOVE! The following AllWebMenus linking code section must always be placed right AFTER the BODY tag-->
<!-- ******** BEGIN ALLWEBMENUS CODE FOR notLoggedIn ******** -->
<script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="notLoggedIn",awmBN="808";awmAltUrl="";</script>
<script charset="UTF-8" src="notLoggedIn.js" type="text/javascript"></script>
<script type="text/javascript">awmBuildMenu();</script>
<!-- ******** END ALLWEBMENUS CODE FOR notLoggedIn ******** -->
<div id="homeWrapper">
  <div id="headerWrapper">
    <div id="headerLogo"><a href="index.php"><img src="images/HeaderLogo.jpg" alt="Women in Health Administration" width="697" height="169" border="0" /></a></div>
    <div id="headerRight">
      <div id="headerSearch"><form action="http://www.whasocal.org/search_results.php" id="cse-search-box" target="_blank">
  <div><img src="images/spacer.gif" width="40" height="13"><br>
    <input type="hidden" name="cx" value="004114537389367705019:xh9_lxgaxq4" />
    <input type="hidden" name="cof" value="FORID:9" />
    <input type="hidden" name="ie" value="UTF-8" />
    <input type="text" name="q" size="25" />
    <input type="submit" name="sa" value="Search" />
  </div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&lang=en"></script>
</div>
      <div id="headerLogin">
<? include "login.php" ?>
	  </div>
      <div id="headerJoin"> Not a Member?<br />
        <a href="memb_application.php" class="wheat">JOIN NOW! </a></div>
    </div>
  </div>
  <div id="bodyWrapper1">
	<table>
		<tr>
			<td valign="top" width="38%"><img src="images/spacer.gif" width="340" height="10"><br><img src="animate/myanimation.gif"></td>
			<td valign="top" width="32%" style="font-size: 14px; font-family: Arial; color: #CAB69E;"><img src="images/spacer.gif" width="315" height="10"><br>
			<? print $mt['opening']; ?></td>
			<td><img src="images/spacer.gif" width="40" height="5"></td>
			<td valign="top" rowspan="2"><br>
	<? if ($nev != 0) {
		if ($nev >= 2) {
			$nlim = 2;
		} else {
			$nlim = 1;
		}
		for ($i = 0; $i < $nlim; $i++) { 
			$erow = mysql_fetch_row($resev);
			$uctitle = strtoupper($erow[2]);
			$dt = $erow[8];
			$dtsecs = mktime(substr($dt,11,2), substr($dt,14,2),0,substr($dt,5,2), substr($dt,8,2), substr($dt,0,4));
			$str = date('l, F j, Y', $dtsecs) . "<br>" . date('g:i A', $dtsecs) . "<br>" . $erow[11];
			$str = $str . "<br>" . $erow[13];

//		format date & time per Susan			
		?>
			<h2 style="text-align: center;" class="title"><? print $uctitle; ?></h2>
			<span style="font-size: 14px; font-family: Arial; color: #4E6C8E;	"><? print $str; ?></span><br>
			<div style="font-size: 12px; font-family: Arial; margin-top:8px"><a href="event.php?eid=<? print $erow[0]; ?>">Info/Registration</a></div><br>
	<?		if ($i == 0 && $nlim == "2") { ?>
			<br>
			<img src="images/gold_horiz.jpg" width="200" height="12"><br><br>
		<?	} 
		} 
	   } else { ?>
	   <span class="ltbl"><? print $a4txt; ?></span><br><br>
	<? } ?>		
	   <img src="images/spacer.gif" width="50" height="18"><br><a href="join_mailing_list.php"><b>Join Our Mailing List</b></a>	
			</td>
			<td width="2%" rowspan="2">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2" valign="top">
			<table>
				<tr>
					<td><img src="images/spacer.gif" width="20" height="5"></td>
					<td width="310" valign="top" class="<? print $ft2; ?>"><img src="images/spacer.gif" width="50" height="10"><br><? print $text2; ?></td>
					<td><img src="images/spacer.gif" width="9" height="30"><br><img src="images/gold_vert.jpg" width="9" height="153"></td>
					<td><img src="images/spacer.gif" width="10" height="5"></td>
					<td valign="top" class="<? print $ft3; ?>"><img src="images/spacer.gif" width="50" height="10"><br><? print $text3; ?></td>
				</tr>

			</table>
			</td>
			<td>&nbsp;</td>
		</tr>
	</table>
	<table>
		<tr>
			<td>
			<? include "spons_block.php"; ?>
			</td>
		</tr>
	</table>

  </div>
<? include "footer1.php"; ?>
</div>
</body>
</html>

Open in new window

What happens when you can't connect to the database?
(This can occurs when there are many accesses to the indxe page).

If this page causes an exception, you'll get a 500 Apache error.
First thing I see is that you do not check whether what you were trying to do was successful, i.e. connect to the database, generate the query against the database, etc.

The issue might be that the connection was not established, the query did retrn data but when you were building the array, the system lacked resources and generated an error.
The error log is likely an indicator, checking if you can run php in debug/error logging might be another option to narrow the situation down.
To BigRat & arnold.

Yes, that's a possibility. But ALL the other pages in the site connect in EXACTLY the same way & none of the others have EVER had a 500 error. It's ONLY this main page.

I have put in a request to support at the host asking how to get at the error logs. I'ts a huge bureaucratic host so it will probably be tomorrow before they respond.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of crazedsanity
crazedsanity
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The system might be configured with connection pooling, such that the first connect to the mysql database will take the longest while subsequent access will be instantaneous.
Without error checking in the php code, there is no way to know where and why an error occurred.
To crazedsanity:

I suspect you are on the right track. I looked at that code (that I wrote) & I can't figure it out myself.

Not a good sign.

The objective is to display different "default" text randomly  in different places on each page load. I need to redo how I'm doing that. It makes no sense when I look now.

I will do that & if that clears it up (I THINK it will), you'll get the points.
Eliminated the while loops, used a slightly different approach.

Loads instantly.

Thanks!
@rkorts: those types of problems can be a real bugger to find.  Glad I could help!