克服“无法显示页面,因为发生了内部服务器错误.”没有任何启用错误报告的选项


Getting over the "The page cannot be displayed because an internal server error has occurred." without any option to enable error reporting

我有一个非常愚蠢的问题,我不知道如何解决它。我的一个客户想让我在他的网站上放一个简单的PHP脚本,这个脚本托管在Windows/PHP共享主机上。

问题是,他们禁用了错误报告,而我无法访问错误日志。我唯一得到的是

无法显示该页面,因为发生了内部服务器错误。

我试过了

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
foreach(1 as $i);
?>

但它没有改变任何东西,我仍然得到通用的500错误。还有其他方法可以让PHP显示错误信息吗?主机技术支持完全没有响应,但我想以某种方式解决这个问题,即使使用一些黑客手段,这意味着我不在乎解决方案有多脏,我所关心的是我可以详细看到错误消息。

我试着像你们建议的那样添加自定义错误处理程序,但我仍然得到500页,没有写错误日志

<?php
date_default_timezone_set("Europe/Prague"); // tried commenting this line out, didn't help
function fileLogHandler($errno, $errstr, $errfile, $errline) {
    $logFile = "error.log";
    $f = fopen($logFile, "a") or die("Couldn't open log file for write");
    fwrite($f, strftime("%c") . " $errstr on line $errline'nin file $errfile'n'n");
}
set_error_handler("fileLogHandler");
foreach(1 as $i);
?>

当我在本地机器上执行此命令时,它按预期工作

$ php -f test.php  && cat error.log 
Fri Oct 28 15:40:14 2011 Invalid argument supplied for foreach() on line 12
in file /Users/darth/Sites/shalamar/test.php

,但它不能在主机上工作…

我试着把整个脚本简化成

<?php
$logFile = "error.log";
$f = fopen($logFile, "a");
fwrite($f, "Hi");
?>

并最终意识到,我可能没有对文件夹的写权限。问题是,这是一个windows服务器,如果我试图通过FileZilla更改权限,我得到可爱的

Command:    SITE CHMOD 666 error.log
Response:   500 'SITE CHMOD 666 error.log': command not understood

我试着谷歌一下,看起来我不能通过FTP设置文件权限

通过电子邮件发送日志也会以500 error结束

mail("mysecret@email.com", "Voice of desperation");
现在有什么建议吗?

Update:感谢到目前为止所有的建议,但是我发现我甚至没有访问文件系统的权限,所以我无法写入日志文件。至少看起来是这样,所以我和技术支持人员谈过了,他们说他们会在下周内调查这个问题。

这就是错误日志的作用。

尝试在包含

的同一目录下创建.user.iniphp.ini文件
error_log = phperrors.log 

(优先选择绝对路径)

然后再次运行脚本,然后查找该文件及其内容。

如何使用set_error_handler()然后将错误消息写入文件?

通过电子邮件获取PHP错误:

function custom_error_handler ($errno, $errstr, $errfile, $errline){
    $content  = "Time ".date("d.m.Y G:i")."'n'n";
    $content .= "Error No: ".$errno."'n";
    $content .= "Error String: ".$errstr."'n";
    $content .= "Error File: ".$errfile."'n";
    $content .= "Error Line: ".$errline."'n'n";
    mail("youremail@yourdomain.com", "[ERROR HANDLER]", $content);
}
set_error_handler ("custom_error_handler");