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

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

Posted by: admin November 30, 2017 Leave a comment

Questions:

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

Answers:

So, if anyone else is having this problem, here’s what you do.

  1. Get out of the VM
  2. Using the console, go to your synced folder (vagrant)
  3. $ sudo chmod -R 777 app/storage

Even though I created the project within the VM using the VM user, the folder belonged to the user in the real computer; so, whent trying to did chmod 777 I got chmod 775.

Now it’s working.

Thanks to all those that helped me figure this thing out

EDIT:

Actually, it wasn’t working, it still gave me a “permission denied” problem.

Here’s what I did, I modified my Vagrantfile like this:

config.vm.synced_folder "./app","/var/www/", create:true,
:owner => "vagrant",
:group => "www-data",
:mount_options => ["dmode=775","fmode=664"]

Questions:
Answers:

Sometimes we need to do more, because

chmod -R 775 storage

Means

7 - Owner can write
7 - Group can write
5 - Others cannot write!

If your webserver is not running as Vagrant, it will not be able to write to it, so you have 2 options:

chmod -R 777 storage

or change the group to your webserver user, supposing it’s www-data:

chown -R vagrant:www-data storage

Questions:
Answers:

You need to adjust the permissions of storage and bootstrap/cache.

  • cd into your Laravel project.
  • sudo chmod -R 777 storage
  • sudo chmod -R 777 bootstrap/cache

Depending on how your web server is setup, you may be able to be more specific with your permissions, and only grant them to your web server user. Google WEB SERVER NAME Laravel file permissions for more information.

At the time of writing, this is for Laravel 5.4

Questions:
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) as group.
You can try this:

sudo chown -R {your current user}:www-data storage
sudo chown -R {your current user}:www-data bootstrap/cache

then to set directory permission try this:

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

Questions:
Answers:

This solution is specific for laravel 5.5

You have to change permissions to a few folders:
chmod -R -777 storage/logs
chmod -R -777 storage/framework
for above folders 775 or 765 did not work for my project

chomd -R 775 bootstrap/cache

Also the ownership of the project folder should be (current user):(web server user)