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

Never use 777 for directories on your live server, but on your own machine, sometimes we need to do more than 775, 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

To fix this issue, you need to change the ownership of the directory to the unix user that the webserver uses.

  1. Get out of the VM
  2. Using the console, go to your synced folder (vagrant)
  3. sudo chown -R $USER:www-data storage
  4. chmod -R 775 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, when trying to

Now it's working.

Thanks to all those that helped me figure this thing out

EDIT:

Actually, it still 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"]

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)'

Tags:

Php

Laravel