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

2020-01-23 10:01发布

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

标签: php laravel
19条回答
劫难
2楼-- · 2020-01-23 10:42

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"]
查看更多
我只想做你的唯一
3楼-- · 2020-01-23 10:43

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
查看更多
▲ chillily
4楼-- · 2020-01-23 10:44

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 the above folders 775 or 765 did not work for my project

chmod -R 775 bootstrap/cache 

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

查看更多
趁早两清
5楼-- · 2020-01-23 10:45

For this error:

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

use this command in terminal:

sudo chmod -R 777 storage
查看更多
爷、活的狠高调
6楼-- · 2020-01-23 10:47

You could do:

chcon -R -t httpd_sys_rw_content_t storage
查看更多
来,给爷笑一个
7楼-- · 2020-01-23 10:48

Add to composer.json

"scripts": {
    "post-install-cmd": [
          "chgrp -R www-data storage bootstrap/cache",
          "chmod -R ug+rwx storage bootstrap/cache"
     ]
}

After composer install

查看更多
登录 后发表回答