Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

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

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 Stack trace: #0 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): MonologHandlerStreamHandler->write(Array) #1 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(337): MonologHandlerAbstractProcessingHandler->handle(Array) #2 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(616): MonologLogger->addRecord(400, Object(UnexpectedValueException), Array) #3 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): MonologLogger->error(Object(UnexpectedValueException), Array) #4 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(113): IlluminateLogWriter->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 Stack trace: #0 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): MonologHandlerStreamHandler->write(Array) #1 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(337): MonologHandlerAbstractProcessingHandler->handle(Array) #2 /var/www/public/blog_project/vendor/monolog/monolog/src/Monolog/Logger.php(616): MonologLogger->addRecord(400, Object(SymfonyComponentDebugExceptionFatalErrorException), Array) #3 /var/www/public/blog_project/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): MonologLogger->error(Object(SymfonyComponentDebugExceptionFatalErrorException), Array) #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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...