Laravel 5 没有收到任何错误日志
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36113032/
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
Laravel 5 not getting any error logs
提问by SamXronn
I installed Laravel 5 on a new VPS, I was running everything fine but I noticed I wasn't getting any Laravel errors the system would only fire a server 500 error at me which is no help when debugging my code.
我在新的 VPS 上安装了 Laravel 5,我运行一切正常,但我注意到我没有收到任何 Laravel 错误,系统只会向我触发服务器 500 错误,这在调试我的代码时没有帮助。
When I looked in the laravel storage/log
it was empty which was strange because I had set the correct file permissions of 777
.
当我查看 laravel 时,storage/log
它是空的,这很奇怪,因为我设置了正确的777
.
So how do I get laravel logs? Why aren't they being written to my storage/log
file.
那么我如何获得 Laravel 日志呢?为什么它们没有被写入我的storage/log
文件。
回答by SamXronn
If you've set your file permissions correctly on the /storage
file directory and you're running on a VPS no shared hosting you might want to check your apache log, inside var/log/apache2/error.log
如果您在/storage
文件目录上正确设置了文件权限,并且您在没有共享主机的 VPS 上运行,您可能需要检查您的 apache 日志,在里面var/log/apache2/error.log
Here you might just see a line that read something along the lines of /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
在这里,您可能只看到一行,上面写着 /var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
Well this is strange because you have the correct file permissions...
嗯,这很奇怪,因为您拥有正确的文件权限...
Let's start by SSH'ing into your VPS head to the directory where laravel is installed normally cd /var/www/html
让我们从 SSH 进入你的 VPS 开始,进入 laravel 正常安装的目录 cd /var/www/html
In here if you run ls -l
You should get some results similar to this image below:
在这里,如果你运行ls -l
你应该得到一些类似于下图的结果:
Notice how we've been accessing the site as the root user, this is our problem and we can confirm this by running ps aux | grep apache2
注意我们是如何以 root 用户身份访问站点的,这是我们的问题,我们可以通过运行来确认这一点 ps aux | grep apache2
You can see here apache2 is running as the user www-data, which is normal for apache. Which means when our laravel installation trys to move files either using ->move()
or just trying to write the log file it fails as the www-data user doesn't have permission. So you can change to this www-data
user by running: chown -R www-data:www-data *
(shorthand for same user/group chown -R www-data. *
)
可以看到 apache2 以用户 www-data 运行,这对 apache 来说是正常的。这意味着当我们的 laravel 安装->move()
尝试使用或仅尝试写入日志文件来移动文件时,它会失败,因为 www-data 用户没有权限。因此,您可以www-data
通过运行更改为该用户:(chown -R www-data:www-data *
相同用户/组的简写chown -R www-data. *
)
Now if you run ls -l
in your www/html
directory you should see root user changed to www-data:
现在,如果您ls -l
在www/html
目录中运行,您应该看到 root 用户更改为 www-data:
This means were now editing the files as the www-data user which has permission, so any changes you make via SFTP should reflect this user change. Fixed!
这意味着现在正在以具有权限的 www-data 用户身份编辑文件,因此您通过 SFTP 所做的任何更改都应反映此用户更改。固定的!
Edit - This is the first time I answered my own question hopefully it's okay.
编辑 - 这是我第一次回答我自己的问题,希望没问题。