Laravel 5 - ErrorException 无法打开流:权限被拒绝

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

Laravel 5 - ErrorException failed to open stream: Permission denied

laravellaravel-5.1

提问by ajtrichards

I've just git clonea repository of mine containing a Laravel 5.1 project. I've gone through the normal steps to get it up and running (setup the webserver, db, etc). I've now gone to the web address I configured and i'm getting the following error message:

我只有git clone一个包含 Laravel 5.1 项目的存储库。我已经完成了启动和运行的正常步骤(设置网络服务器、数据库等)。我现在已经转到我配置的网址,并且收到以下错误消息:

ErrorException in compiled.php line 6648:
file_put_contents(/3c7922efc24ab13620cd0f35b1fdaa61): failed to open stream: Permission denied

Any idea's what folder it's trying to access?

知道它试图访问哪个文件夹吗?

回答by ajtrichards

To solve this problem I needed to create a few folder's that were missing from my install. You require the following folders to be readable and writable by your www user:

为了解决这个问题,我需要创建一些我的安装中缺少的文件夹。您需要 www 用户可以读写以下文件夹:

/storage
/storage/cache
/storage/framework
/storage/framework/sessions
/storage/framework/views
/storage/framework/cache
/storage/logs

Also, set the folder permissions to 775. From the root directory run the command: sudo chmod -R 755 storage

此外,将文件夹权限设置为775. 从根目录运行命令:sudo chmod -R 755 storage

回答by Carlos R. Bécquer Rodríguez

I solved the problem with this solution, clarifying that if you have Windows, you apply lines 1 and 3 and it works the same.

我用这个解决方案解决了这个问题,澄清了如果你有 Windows,你应用第 1 行和第 3 行,它的工作原理是一样的。

php artisan cache:clear
chmod -R 777 storage/
composer dump-autoload

回答by Carlos

If you're using ubuntu, most likely you have to give permissions to that folder storage

如果您使用的是 ubuntu,很可能您必须授予该文件夹存储的权限

cd into the project and use the command -> sudo chmod 755 storage/*

cd 进入项目并使用命令 -> sudo chmod 755 storage/*

回答by Ali Raza

I had this problem lately with my tests, and resolved it through: composer dump-autoload

我最近在测试中遇到了这个问题,并通过以下方式解决了:composer dump-autoload

回答by Ahmed Osama

I had similar problem in my localhostand the problem was that I was trying to upload a file larger than upload_max_filesizein my php.inifile . just updating this to greater value and restart my server solved the problem ,, if you having similar problem this might be the case

我在我的本地主机中遇到了类似的问题,问题是我试图上传一个比upload_max_filesize我的php.ini文件大的 文件。只需将其更新为更大的值并重新启动我的服务器即可解决问题,如果您遇到类似问题,可能就是这种情况

回答by Pulsar

For me solution was to change folder owner of laravel project. Ensure that is your own user and not root:www-data.

对我来说,解决方案是更改 laravel 项目的文件夹所有者。确保是您自己的用户而不是 root:www-data。

sudo chown -R username:group directory

回答by gboone

For me it was because the single file was owned by root...written at some point when I setup the files, and the app couldn't read it. Solution could be to change ownership, get rid of it, etc.

对我来说,这是因为单个文件由 root 拥有......在我设置文件时的某个时候写的,并且应用程序无法读取它。解决方案可能是更改所有权,摆脱它等。

回答by user728650

If you are on linux (centos) here is what you need to do I am assuming default nginx dir, but yours might be apache and it shuld work for that too [just change the paths accordingly].

如果您使用的是 linux (centos),这里是您需要做的,我假设默认的 nginx 目录,但您的可能是 apache,它也适用于该目录 [只需相应地更改路径]。

sudo chcon -R -t httpd_sys_rw_content_t /usr/share/nginx/html/my-site/dir-to-make-writeable
cd /usr/share/nginx/html
sudo chown -R nginx:nginx ./my-site

This should set the proper context for the web dir

这应该为 web 目录设置正确的上下文