4

When I navigate to Laravel app on my CentOS server, it gives HTTP ERROR 500

enter image description here

So, when I checked my server error log, it says this error

PHP Fatal error:  Uncaught UnexpectedValueException: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107\nStack trace:\n#0 

I have already set 777 permission to storage and bootstrap directories.

This very Laravel application runs fine on another server. So, what's the big deal here ?

Tharindu Thisarasinghe
  • 3,486
  • 7
  • 32
  • 67
  • 2
    it might be related to file permission of SELinux, try searching for it, and try disabling SELinux first, if it is the culprit, then you need to find a way to enable SELinux while allowing your site to function properly – am05mhz Nov 23 '17 at 05:02
  • @am05mhz Ohh I will search for it but, that's to Greek for me since I'm kinda new to this server thing. – Tharindu Thisarasinghe Nov 23 '17 at 05:05
  • here for a starting line https://www.tecmint.com/disable-selinux-temporarily-permanently-in-centos-rhel-fedora/ – am05mhz Nov 23 '17 at 05:06
  • Try this https://stackoverflow.com/questions/31975204/laravel-5-failed-to-open-stream-permission-denied-exception-when-connecting – Ankur Tiwari Nov 23 '17 at 05:09
  • you should never set permissions to 777. Try to `touch /var/www/html/storage/logs/laravel.log` and make your php user the owner, e.g. use `chown`. Then check if it works. – Gordon Nov 23 '17 at 05:51
  • Thanks all of you. Actually, the cause of the problem was SE-Linux. So, thanks again @am05mhz for pointing that out. :) – Tharindu Thisarasinghe Nov 23 '17 at 12:44

2 Answers2

6

This error can be fixed by disabling SE-Linux.

Check if it has been enabled by typing...

$ sestatus

So, disable it by typing...

# setenforce 0

It is said that the system needs to be restarted to to take effect the changes.

However, for me, restarting Apache was enough and fixed the problem :-)

Hope this helps!

Tharindu Thisarasinghe
  • 3,486
  • 7
  • 32
  • 67
  • 5
    it is very bad to keep selinux off !! instead use `chcon -R -t httpd_sys_rw_content_t storage` from the project directory then restart http, – George Mar 20 '18 at 08:57
1

If your application is laravel and you use sail so add these lines in end of .env file:

WWWGROUP=1000
WWWUSER=1000

I know its late to answer but maybe helps for others.

akbar
  • 424
  • 4
  • 11
  • Also, try stopping Docker (if using Laravel Sail), then running: `chown yourusername:yourgroup -R .` (refer to output of `ls -la` in Laravel directory for username/group), `chmod 750 -R .`, start Docker, and run `php artisan route:clear`, `php artisan config:clear`, and `php artisan cache:clear` – Tyler Jun 22 '21 at 17:22