Laravel 5.2 无法打开 laravel.log

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35715400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:19:42  来源:igfitidea点击:

Laravel 5.2 could not open laravel.log

phplaravellaravel-5chmod

提问by csanonymus

I know there are a lot of questions on this topic but my issues is really weird that's why I decided to post. I have this error in /var/logs/apache/error.log

我知道关于这个主题有很多问题,但我的问题真的很奇怪,这就是我决定发布的原因。我有这个错误/var/logs/apache/error.log

  [Tue Mar 01 07:26:51.435312 2016] [:error] [pid 8837] [client 127.0.0.1:37843] PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/var/www/personale/librarie-cor/storage/logs/laravel.log" could not be opened: 
failed to open stream: Permission denied' in /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:87\nStack trace:
\n#0 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)
\n#1 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Logger.php(289): Monolog\Handler\AbstractProcessingHandler->handle(Array)
\n#2 /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Logger.php(565): Monolog\Logger->addRecord(400, Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
\n#3 /var/www/personale/librarie-cor/vendor/laravel/framework/src/Illuminate/Log/Writer.php(202): Monolog\Logger->error(Object(Symfony\Component\Debug\Exception\FatalErrorException), Array)
\n#4 /var/www/personale/librarie-cor in /var/www/personale/librarie-cor/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 87

The thing is I already did chmod -R 777 storage/, here is a screenshot:

事情是我已经做了chmod -R 777 storage/,这是一个截图:

chmoded

chmoded

How can I get rid of the error?

我怎样才能摆脱错误?

采纳答案by csanonymus

I finally found a solution.. Seems like the problem had to do with PSR-4 and auto importing classes

我终于找到了解决方案..似乎问题与 PSR-4 和自动导入类有关

So here's the solution for anyone else having this problem:

因此,这是其他遇到此问题的人的解决方案:

php artisan clear-compiled 
composer dump-autoload
php artisan optimize
php artisan cache:clear

回答by Risan Bagja Pradana

TLDR;

TLDR;

Run the following commands on your terminal

在终端上运行以下命令

# Clear Laravel cache and the compiled classes
php artisan cache:clear
php artisan clear-compiled

# Change the storage and cache directories permission
sudo chmod -R 777 storage
sudo chmod -R 777 bootstrap/cache

# Regenerate the composer autoload file
composer dump-autoload

More thorough explanation

更详尽的解释

This usually happens because of the web server needs a write access to the storageand bootstrap/cachedirectories.

这通常是因为 Web 服务器需要对storagebootstrap/cache目录进行写访问。

1. Check which user is being used by web server process

1. 检查 web 服务器进程正在使用哪个用户

First, make sure that your webserver process is run by an account with limited privileges. Nginx and Apache usually will automatically create and use the less privileged www-datauser and group. You can always use the pscommand to check which user is being used by the running service:

首先,确保您的网络服务器进程由具有有限权限的帐户运行。Nginx 和 Apache 通常会自动创建和使用权限较低的www-data用户和组。您始终可以使用该ps命令来检查正在运行的服务正在使用哪个用户:

ps aux | grep nginx

2. Set the owner of your project directory

2.设置你的项目目录的所有者

Next, make sure that your Laravel project directory is owned by the same user and group who run the web server process. Suppose your web server is run by www-dataand your project directory is located at /var/www/laravel, you can set the ownership like so:

接下来,确保您的 Laravel 项目目录由运行 Web 服务器进程的同一用户和组拥有。假设您的 Web 服务器由 运行www-data并且您的项目目录位于/var/www/laravel,您可以像这样设置所有权:

sudo chown -R www-data:www-data /var/www/laravel

3. Give a write access to storageand cachedirectories

3. 授予对storagecache目录的写访问权限

This is the IMPORTANT step, make sure you give the write permission both to storageand bootstrap/cachedirectories.

这是重要的步骤,请确保您授予对storagebootstrap/cache目录的写权限。

sudo chmod -R 775 /var/www/laravel/storage
sudo chmod -R 775 /var/www/laravel/bootstrap/cache

Still Not Working?

还是行不通?

If the above steps are still not working, you can try to run the following commands in the shell:

如果以上步骤还是不行,可以尝试在shell中运行以下命令:

# 1. Clear Laravel cache
php artisan cache:clear

# 2. Delete the compiled class
php artisan clear-compiled

# 3. Regenerate the composer autoload file
composer dump-autoload

Yet, it still not working?

然而,它仍然不起作用?

For the last resource, try to set the permission to 777which means any users will have the ability to read and write to the given directories.

对于最后一个资源,尝试设置权限,777这意味着任何用户都可以读取和写入给定目录。

sudo chmod -R 777 /var/www/laravel/storage
sudo chmod -R 777 /var/www/laravel/bootstrap/cache

Hope this help.

希望这有帮助。

回答by jacobfogg

I had the same issue with Centos7 ... I tried EVERYTHING. Finally, I found a post on stackoverflow suggesting it could be selinux. I disabled selinux and it worked!

我在 Centos7 上遇到了同样的问题......我尝试了一切。最后,我在 stackoverflow 上找到了一个帖子,建议它可能是 selinux。我禁用了 selinux,它起作用了!

回答by Jickson Johnson Koottala

If you are in Centos, then disable SELinux enforcement

如果您在 Centos 中,则禁用 SELinux 强制执行

run below command to do this.

运行下面的命令来做到这一点。

setenforce 0

In my case, this solution worked very well. Hope this will help.

就我而言,此解决方案效果很好。希望这会有所帮助。

回答by Abrar Jahin

U should try somethings like this-

你应该尝试这样的事情-

php artisan cache:clear
php artisan clear-compiled

sudo chmod -R 777 storage/ -R
composer dump-autoload

U can go to this questionfor more details.

你可以去这个问题了解更多详情。

回答by karrar kazuya

use this

用这个

chcon -R -t httpd_sys_rw_content_t storage

chcon -R -t httpd_sys_rw_content_t 存储