laravel 如何在laravel 4上显示错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14568426/
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
How to display errors on laravel 4?
提问by Blue Genie
I'm trying to create an app on Laravel 4 beta but I can't debug it because it doesn't show any error, display_errors
is on, error_reporting
is E_ALL
and debug => true
(config/app.php
). When I try to do an error on public/index.php
it shows a parse error, but when I do it on the router it just shows a blank page (White screen of death). How can I fix this?
我正在尝试在 Laravel 4 测试版上创建一个应用程序,但我无法调试它,因为它没有显示任何错误、display_errors
打开、error_reporting
是E_ALL
和debug => true
( config/app.php
)。当我尝试在public/index.php
它上面做一个错误时会显示一个解析错误,但是当我在路由器上做它时它只显示一个空白页面(白屏死机)。我怎样才能解决这个问题?
Thank you
谢谢
回答by Laurence
@Matanya- have you looked at your server logs to see WHAT the error 500 actually is? It could be any number of things
@Matanya- 您是否查看了服务器日志以了解错误 500 究竟是什么?它可以是任意数量的东西
@Aladin- white screen of death (WSOD) can be diagnosed in three ways with Laravel 4.
@Aladin- Laravel 4 可以通过三种方式诊断白屏死机 (WSOD)。
Option 1:Go to your Laravel logs (app/storage/logs) and see if the error is contained in there.
选项 1:转到您的 Laravel 日志(应用程序/存储/日志)并查看错误是否包含在其中。
Option 2:Go to you PHP server logs, and look for the PHP error that is causing the WSOD
选项 2:转到 PHP 服务器日志,并查找导致 WSOD 的 PHP 错误
Option 3:Good old debugging skills - add a die('hello') command at the start of your routes file - then keep moving it deeper and deeper into your application until you no longer see the 'hello' message. Using this you will be able to narrow down the line that is causing your WSOD and fix the problem.
选项 3:良好的旧调试技巧 - 在路由文件的开头添加 die('hello') 命令 - 然后继续将其移动到应用程序中越来越深,直到您不再看到 'hello' 消息。使用它,您将能够缩小导致 WSOD 的范围并解决问题。
回答by cw24
I had a problem with the white screen after installing a new laravel instance. I couldn't find anything in the logs because (eventually I found out) that the reason for the white screen was that app/storage wasn't writable.
安装新的 Laravel 实例后出现白屏问题。我在日志中找不到任何内容,因为(最终我发现)白屏的原因是应用程序/存储不可写。
In order to get an error message on the screen I added the following to the public/index.php
为了在屏幕上显示错误消息,我将以下内容添加到 public/index.php
try {
$app->run();
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
After that it was easy to solve the problem.
之后问题就很容易解决了。
回答by John Doe
Go to app/config/app.php
转到 app/config/app.php
and set 'debug' => true,
并设置“调试”=> 真,
回答by Hasnat Safder
Inside config folder open app.php
里面的配置文件夹打开 app.php
Change
改变
'debug' => false,
to
到
'debug' => true,
回答by Matanya
Following the good advice by @The Shift Exchange I looked at the error_log and indeed managed to solve to problem. it was simply a permissions issue:
按照@The Shift Exchange 的好建议,我查看了 error_log 并确实设法解决了问题。这只是一个权限问题:
Tue Feb 26 11:22:20 2013] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/Users/matanya/Sites/indgo/app/start/../storage/logs/log-apache2handler-2013-02-26.txt" could not be opened: failed to open stream: Permission denied' in /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:71\nStack trace:\n#0 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php(77): Monolog\Handler\StreamHandler->write(Array)\n#1 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\RotatingFileHandler->write(Array)\n#2 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Logger.php(217): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#3 /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Logger.php(281): Monolog\Logger->addRecord(400, Object(ErrorException), Array)\n#4 [internal function]: Monolog\Logger->addError(Object(ErrorException))\n#5 /Users/matanya/Sites/in in /Users/matanya/Sites/indgo/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 71
Once I used chmod
to apply less stringent permissions, all went back to normal.
一旦我曾经chmod
应用不太严格的权限,一切都会恢复正常。
However, I'm not sure that it answers the OP's question, as he was getting a blank screen rather than a server error.
但是,我不确定它是否回答了 OP 的问题,因为他看到的是空白屏幕而不是服务器错误。
回答by TheRealJAG
In the Laravel root folder chmod the storage directory to 777
在Laravel根文件夹chmod存储目录为777
回答by Oluwatobi Samuel Omisakin
Maybe not on Laravel 4 this time, but on L5.2* I had similar issue:
这次可能不是在 Laravel 4 上,但在 L5.2* 上我遇到了类似的问题:
I simply changed the ownership of the storage/logs
directory to www-data
with:
我只是将storage/logs
目录的所有权更改为www-data
:
# chown -R www-data:www-data logs
PS: This is on Ubuntu 15 and with apache.
PS:这是在 Ubuntu 15 和 apache 上。
My logs
directory now looks like:
我的logs
目录现在看起来像:
drwxrwxr-x 2 www-data www-data 4096 jaan 23 09:39 logs/
回答by Grant
Further to @cw24's answer • as of Laravel 5.4
you would instead have the following amendment in public/index.php
继@cw24 的回答 • 从 Laravel 开始,5.4
您将改为在public/index.php
try {
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
} catch(\Exception $e) {
echo "<pre>";
echo $e;
echo "</pre>";
}
And in my case, I had forgotten to fire up MySQL.
Which, by the way, is usually mysql.server start
in Terminal
就我而言,我忘记启动 MySQL。
顺便说一句,通常mysql.server start
在终端
回答by Rahul Hirve
Just go to your app/storage/logs
there logs of error
available. Go to filename of today's date time and you will find latest error
in your application.
只需转到您app/storage/logs
的error
可用日志。转到今天日期时间的文件名,您将error
在应用程序中找到最新的。
OR
或者
Open app/config/app.php
and change setting
打开app/config/app.php
并更改设置
'debug' => false,
To
到
'debug' => true,
OR
或者
Go to .env
file to your application and change the configuratuion
转到.env
文件到您的应用程序并更改配置
APP_LOG_LEVEL=debug
回答by Ajay Patel
https://github.com/loic-sharma/profilerthis is good example for alternative to laravel3 debug bar.
https://github.com/loic-sharma/profiler这是替代 laravel3 调试栏的好例子。