Laravel:file_put_contents() 无法打开流:会话文件夹的权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38888568/
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 14:18:05  来源:igfitidea点击:

Laravel: file_put_contents() failed to open stream: Permission denied for Session folder

laravellaravel-5

提问by Harsimran Singh

I am getting this issue for sessions even when I have given 777 and required user and group to the folders in storage.

即使我为存储中的文件夹提供了 777 和所需的用户和组,我也遇到了会话问题。

ErrorException in Filesystem.php line 81: file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied

Filesystem.php 第 81 行中的 ErrorException:file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec):无法打开流:权限被拒绝

How can I get rid of this issue?

我怎样才能摆脱这个问题?

at HandleExceptions->handleError('2', 'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): failed to open stream: Permission denied', '/var/www/html/business/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '81', array('path' => '/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec', 'contents' => 'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:"http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s:1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}}', 'lock' => true))

在 HandleExceptions->handleError('2', 'file_put_contents(/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec): 未能打开流: 权限无功/拒绝/www/html/business供应商/laravel/framework/src/Illuminate/Filesystem/Filesystem.php', '81', array('path' => '/var/www/html/business/storage/framework/sessions/2b184c1b05d6d2af943d9a4e48875301321a56ec', => 'a:5:{s:6:"_token";s:40:"Dyi8ML8zxaQJOEiVvqBpqk3noLDJTkIdqiC67qs9";s:9:"_previous";a:1:{s:3:"url";s:29:" http://XXXXX:8333";}s:22:"PHPDEBUGBAR_STACK_DATA";a:0:{}s:9:"_sf2_meta";a:3:{s:1:"u";i:1470895812;s :1:"c";i:1470895812;s:1:"l";s:1:"0";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}} ', '锁' => 真))

回答by geneowak

I had a problem like that and doing the following solved it for me

我遇到了这样的问题,执行以下操作为我解决了

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

Got it from the answer here

这里的答案中得到它

回答by Richie Rizal Amir

if you try

如果你试试

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

chmod -R gu+w 存储

chmod -R guo+w 存储

php artisan 缓存:清除

and it still doesn't work.

它仍然不起作用。

you have two ways:

你有两种方法:

  1. Disable your SELinux (i really don't recommend this way, unless you are on training or learning)

  2. Configuring SELinux Policies for Apache Web Servers

  1. 禁用您的 SELinux(我真的不推荐这种方式,除非您正在接受培训或学习)

  2. 为 Apache Web 服务器配置 SELinux 策略

i want to break down every steps for confirguring selinux policies assumption: you've already installed all database like mysql, postgresql, or others. you've installed web server

我想分解配置 selinux 策略假设的每个步骤:您已经安装了所有数据库,如 mysql、postgresql 或其他。你已经安装了网络服务器

  1. install semanage with command "yum provides /usr/sbin/semanage"
  2. install policycoreutils-python with command "yum install -y policycoreutils-python"
  3. create policies:

a. sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"

b. sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"

c. sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"

  1. Allowing ReadWrite Access:

a. sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"

  1. 使用命令“yum提供/usr/sbin/semanage”安装semanage
  2. 使用命令“yum install -y policycoreutils-python”安装 policycoreutils-python
  3. 创建策略:

一种。sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/webapp(/.*)?"

湾 sudo semanage fcontext -a -t httpd_log_t "/var/www/html/webapp/logs(/.*)?"

C。sudo semanage fcontext -a -t httpd_cache_t "/var/www/html/webapp/cache(/.*)?"

  1. 允许读写访问:

一种。sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/webapp/storage(/.*)?"

ACCESS YOUR WEBAPP

访问您的 WEBAPP

b. restorecon -Rv /var/www/html/webapp

湾 restorecon -Rv /var/www/html/webapp