services.json 无法打开流:Laravel 4 中的权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17954625/
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
services.json failed to open stream: Permission denied in Laravel 4
提问by JasonStockman
I was playing around with a working Laravel 4 installation and moved everything into a sub folder. Then I decided to not do that and I moved it all back (all via the command line):
我正在玩一个工作的 Laravel 4 安装并将所有内容移动到一个子文件夹中。然后我决定不这样做,并将其全部移回(全部通过命令行):
mv * /folder
and then
进而
cd folder
mv * ../
Now, the site is throwing the following error:
现在,该站点抛出以下错误:
file_put_contents(/var/www/quantquote/app/storage/meta/services.json): failed to open stream: Permission denied
Here is a screenshot of the full error:
这是完整错误的屏幕截图:
http://i.imgur.com/8deGG97.png
http://i.imgur.com/8deGG97.png
I've already tried setting permissions on the /storage folder to 777 to no avail.
我已经尝试将 /storage 文件夹的权限设置为 777 无济于事。
回答by Sky
Spent a whole day for solving this and this command simply solved my problem.
花了一整天的时间来解决这个问题,这个命令简单地解决了我的问题。
If your permissions are 777 for Laravel App folder and you still get this error, it's because SEliuxhas blocked it. You can easily unblock your application's folder using this command:
如果您对 Laravel App 文件夹的权限为 777 并且仍然出现此错误,那是因为SEliux已阻止它。您可以使用以下命令轻松取消阻止应用程序的文件夹:
su -c "chcon -R -h -t httpd_sys_script_rw_t /usr/share/nginx/YOUR_LARAVEL_APP/"
su -c "chcon -R -h -t httpd_sys_script_rw_t /usr/share/nginx/YOUR_LARAVEL_APP/"
That's it!
就是这样!
BTW never disable SElinux: http://stopdisablingselinux.com/
顺便说一句,永远不要禁用 SElinux:http://stopdisablingselinux.com/
回答by Collin Henderson
As I stated in my comment:
正如我在评论中所说:
find app/storage -type d -exec chmod 777 {} \;
find app/storage -type d -exec chmod 777 {} \;
find app/storage -type f -exec chmod 777 {} \;
find app/storage -type f -exec chmod 777 {} \;
This will chmod all directories and files in app/storage
to 777.
这会将所有目录和文件 chmodapp/storage
到 777。
回答by Rubens Mariuzzo
As the problem is related to permissionstry re-giving the right permissions to app/storage
and all its sub-directories and file.
由于问题与权限有关,请尝试重新授予其app/storage
所有子目录和文件的正确权限。
You can do so from the root path of your Laravel app typing:
您可以从 Laravel 应用程序的根路径输入:
chmod -Rvc 777 app/storage
If for some reason this doesn't work, try:
如果由于某种原因这不起作用,请尝试:
find app/storage -type d -exec chmod -vc 777 {} \;
find app/storage -type f -exec chmod -vc 777 {} \;
回答by Eric Estrada Gómez
If you're using CentOS7, follows these steps:
如果您使用 CentOS7,请按照以下步骤操作:
Change app/storage directory ownership
chown apache:apache app/storage
Change app/storage permissions
chmod -R 775 app/storage
Prevent SELinux from blocking the app/storage directory
su -c "chcon -R -h -t httpd_sys_script_rw_t [fullpath]/app/storage"
更改应用程序/存储目录所有权
chown apache:apache app/storage
更改应用程序/存储权限
chmod -R 775 app/storage
防止 SELinux 阻塞 app/storage 目录
su -c "chcon -R -h -t httpd_sys_script_rw_t [fullpath]/app/storage"
回答by Igor Parra
When chmod 777 or chmod 775 fails check that subdirectories really exists:
当 chmod 777 或 chmod 775 失败时,请检查子目录是否确实存在:
app/storage/
├── cache
├── logs
├── meta
├── sessions
└── views
in case these folders does not exists you must to create it:
如果这些文件夹不存在,您必须创建它:
cd app/storage/
mkdir meta logs cache sessions views
cd ../
find storage -type d -exec chmod 775 {} \;
find storage -type f -exec chmod 664 {} \;
UPDATE 2016 for laravel 5+
更新 2016 为 laravel 5+
In a default Laravel 5+ application structure, storage
is at the same level than app
. So the previous command becomes:
在默认的 Laravel 5+ 应用程序结构中,storage
与app
. 所以之前的命令变成了:
cd storage/
mkdir meta logs cache sessions views
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;
回答by AmirAgha
just type this on terminal:
只需在终端上输入:
php artisan cache:clear
回答by Fran?ois
Never run a 777, in recursive mode. It's a security issue. For now, remove the services.json file, and try this :
永远不要在递归模式下运行 777。这是一个安全问题。现在,删除 services.json 文件,然后试试这个:
回答by Mahendra Parab
Try these commands one by one:
一一试试这些命令:
setenforce 0
setsebool -P httpd_can_network_connect_db on