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:51

It also may be SELinux. (Centos, RedHat)

Determine status of SElinux on terminal:

$ sestatus

If status is enabled, write command to disable SElinux

$ setenforce Permissive

Or you may execute this command

$ sudo setenforce 0

查看更多
祖国的老花朵
3楼-- · 2020-01-23 10:51

This error can be fixed by disabling Linux.

Check if it has been enabled

sestatus

You try..

setenforce 0

查看更多
【Aperson】
4楼-- · 2020-01-23 10:52

I wasn't too keen on changing my folder permissions to 777. Here's how I went about fixing this issue.

First, I changed the user who is running the web server on my local machine(I run nginx, but the principles apply everywhere):

$> sudo vim /etc/nginx/nginx.conf
user <my_user> #inside nginx.conf
service nginx reload

Afterwards, I created another index.php file under the public/ folder to find out who was running my php-fpm version and where I would go about changing that:

<?php
phpinfo();
?>

Reloading the page, I found out that www-data was the user(under the environment section). I also found out I was running php 7.1. I proceeded to change the user:

$> sudo vim /etc/php/7.0/fpm/pool.d/www.conf 
#Look for www-data or the following variables: user, group, listen.user, listen.group.

Finally, I gave the following permissions to folders:

sudo chmod -R 775 ./storage/

Now, I made sure that I was the owner of the folders by using a simple:

ls -al

If you set the server and php-fpm users to yourself and the folders are owned by root for example, then you will keep encountering this issue. This can happen if you did a sudo laravel new <project> as root. In that case, make sure you use a recursive chown command on your project to change the user:group settings. In most default cases, www-data is the main setting for the server and php, in that case it's a matter of making sure the folder isn't out of www-data's reach.

My project is setup in my home directory. On Ubuntu 16.04 and Laravel 5.5.

查看更多
爷、活的狠高调
5楼-- · 2020-01-23 10:53

Fixed my problem with this command in centos 7.6 Server

chcon -R -t httpd_sys_content_t $SITE_PATH

chcon -R -t httpd_sys_rw_content_t $SITE_PATH
查看更多
我命由我不由天
6楼-- · 2020-01-23 10:54

(on Ubuntu) : Can be solved in 2 simple steps :

$ sudo chmod -R 777 storage 

And

$ sudo service apache2 restart
查看更多
手持菜刀,她持情操
7楼-- · 2020-01-23 10:54

Had this issue and found this and it solved the issue.

enter image description here

查看更多
登录 后发表回答