PHP 不显示错误 - 内部服务器错误 (500)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11749043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP not displaying errors - Internal Server Error (500)
提问by iainjames88
I've set up a fresh install of Ubuntu Server 12.04 LTS on Amazon AWS with *Apache2/MySQL/PHP5. When I run a PHP script and it encounters an error I don't see any error reporting from PHP, all I see is
我已经在 Amazon AWS 上使用 *Apache2/MySQL/PHP5 全新安装了 Ubuntu Server 12.04 LTS。当我运行 PHP 脚本并遇到错误时,我没有看到来自 PHP 的任何错误报告,我看到的是
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfil the request.
I have checked my /etc/php5/apache2/php.inifile and as far as I can tell error reporting should be set up. The contents of the file (regarding errors) are:
我已经检查了我的/etc/php5/apache2/php.ini文件,据我所知应该设置错误报告。文件的内容(关于错误)是:
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
Can anyone advise? If I try something like $obj = new ObjectDoesntExist;it doesn't tell me Fatal error: Class 'ObjectDoesntExist'it gives me a server 500 error.
任何人都可以建议吗?如果我尝试类似的东西,$obj = new ObjectDoesntExist;它不会告诉我Fatal error: Class 'ObjectDoesntExist'它会给我一个服务器 500 错误。
Any advise?
有什么建议吗?
* The modules I have installed are: mysql-server mysql-client apache2 php5 libapache2-mod-php5 phpmyadmin. Other than that it is a completely base install of Ubuntu Server 12.04 LTS
* 我安装的模块是:mysql-server mysql-client apache2 php5 libapache2-mod-php5 phpmyadmin. 除此之外,它是 Ubuntu Server 12.04 LTS 的完全基础安装
EDIT:
If I use ini_set('display_errors', '1');at the start of my script it displays errors as normal, but how do I enable this site wide?
编辑:如果我ini_set('display_errors', '1');在脚本的开头使用它会正常显示错误,但是如何在整个站点范围内启用?
采纳答案by Wouter
The php.ini snippet you pasted has a semicolon (the ; character) in each line. The semicolon is the start of a comment in php.ini, so everything in a line following a semicolon is not used. Try manually setting display_errors to on and error_reporting to E_ALL, or removing the appropriate semicolons to fix this.
您粘贴的 php.ini 片段在每一行中都有一个分号(; 字符)。分号是 php.ini 中注释的开始,因此分号之后的行中的所有内容都不会使用。尝试手动将 display_errors 设置为 on 并将 error_reporting 设置为 E_ALL,或删除适当的分号来解决此问题。
Furthermore, check your apache's error log, php might be logging its errors there.
此外,检查您的 apache 的错误日志,php 可能会在那里记录其错误。
回答by user2779489
please edit the php.ini file by using the sudo gedit /etc/php5/apache2/php.ini and on the Production Value,or you can also use the ini_set('display_errors', '1'); at the top of your php file
请使用 sudo gedit /etc/php5/apache2/php.ini 和生产值编辑 php.ini 文件,或者您也可以使用 ini_set('display_errors', '1'); 在你的 php 文件的顶部
回答by mandza
I had the same problem but unrelated with php.ini if you have same error, before you begin snipping on your server, first check your code. Mistake can be a missing } ) or ; or something like that. this is just reference what to do first.
我有同样的问题,但与 php.ini 无关,如果你有同样的错误,在你开始在你的服务器上剪断之前,首先检查你的代码。错误可能是缺少 } ) 或 ; 或类似的东西。这只是参考首先要做什么。

