Solve 500 response Laravel (Uncaught UnexpectedValueException: Laravel.log)

浪尽此生 提交于 2019-12-13 03:20:03

问题


I have a problem with my (new/clean) Laravel (tried v5.2 and v5.5) application on Centos 7. It shows a 500 error when i visited the URL of the application with no error. I checked the log file of apache (/etc/httpd/logs/error-log.log) what contained the 2 errors bellow:

[Mon Dec 04 10:32:34.108956 2017] [:error] [pid 25889] [client 192.168.1.240:63437] PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/public/blog_project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)\n#1 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#2 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(UnexpectedValueException), Array)\n#3 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(UnexpectedValueException), Array)\n#4 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): Illuminate\Log\Writer->writeLog('error', Object(U in /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

&

[Mon Dec 04 10:32:34.109334 2017] [:error] [pid 25889] [client 192.168.1.240:63437] PHP Fatal error: Uncaught UnexpectedValueException: The stream or file "/var/www/public/blog_project/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)\n#1 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(337): Monolog\Handler\AbstractProcessingHandler->handle(Array)\n#2 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(616): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)\n#3 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)\n#4 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.p in /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 107

To solve these problems i Googled a lot. Solutions i found where all related to permissions so I tried to set chmod 777 to all directories and files (for test purposes, not recommended at live environment!) in /var/www/public/blog_project but this did not solve the problem.

I also found that the owner/group could be the problem (unlikely with chmod 777 but ok) so I changed the owner and group to "apache". Unfortunately this did still not solve my problem.

I also tried a "php artisan cache:clear" (suggested in some topic what described the same problem as i have)


回答1:


At the moment of writing i already had found the solution (after many hours of Googling) for my problem but i still want to post this question because i could not find another question what solved my problem. I hope to help other people who have the same problem this way.

The problem was that SELinux was enabled which prevent Apache to write files even with 777 mode. It seems that SELinux is active by Centos 4 or higher by default. I also found that Fedora has SELinux activated what results in the same problem (no own experience with Fedora).

I solved the problem by disabling SELinux. For CentosOS7 id did this by editing /etc/sysconfig/selinux and changing the line SELINUX=enforcing into SELINUX=disabled. After that i rebooted the server and the problem was solved.




回答2:


I solved the problem by disabling SELinux. For CentosOS7 id did this by editing /etc/sysconfig/selinux and changing the line SELINUX=enforcing into SELINUX=disabled. After that i rebooted the server and the problem was solved.

Thanks :)




回答3:


please don't disable your selinux. there is a better way to do it

See this, i posted a better way Laravel: file_put_contents() failed to open stream: Permission denied for Session folder



来源:https://stackoverflow.com/questions/47650406/solve-500-response-laravel-uncaught-unexpectedvalueexception-laravel-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!