Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix Error: laravel.log could not be opened?

Tags:

php

laravel

I'm pretty new at laravel, in fact and I'm trying to create my very first project. for some reason I keep getting this error (I haven't even started coding yet)

Error in exception handler: The stream or file "/var/www/laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/laravel/bootstrap/compiled.php:8423 

I've read this has something to do with permissions but chmod -R 775 storage didn't help at all.

Permissions

like image 955
frankelot Avatar asked May 01 '14 16:05

frankelot


People also ask

Could not be opened in append mode laravel log?

This error occurs because the web server is unable to write into the error logs in the storage folder. Since, the web server will need to be able to write all kinds of files into the storage folder and also the bootstrap/cache folder.

Could not be opened in append mode failed to open stream Permission denied at?

If you encountered an error that says “Could Not Be Opened In Append Mode: Failed To Open Stream: Permission Denied” such us the the image below, you can solve this by simply changing the permission access of certain file. The chmod 666 will allow all users to read and write but cannot execute the file.

Can laravel log delete?

If you're having a space problem you can try using daily logs, it will automatically keep last X days of log (default 5). You can see it in Errors & Logging - Log Storage. Otherwise you can simply remove the storage/logs/laravel. log file or make a command to do so (like php artisane log:clear ).


1 Answers

Never set a directory to 777. you should change directory ownership. so set your current user that you are logged in with as owner and the webserver user (www-data, apache, ...) as the group. You can try this:

sudo chown -R $USER:www-data storage sudo chown -R $USER:www-data bootstrap/cache 

then to set directory permission try this:

chmod -R 775 storage chmod -R 775 bootstrap/cache 

Update:

Webserver user and group depend on your webserver and your OS. to figure out what's your web server user and group use the following commands. for nginx use:

ps aux|grep nginx|grep -v grep

for apache use:

ps aux | egrep '(apache|httpd)'

like image 78
Hamid Parchami Avatar answered Sep 23 '22 22:09

Hamid Parchami