Laravel 4:无法打开流:权限被拒绝

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

Laravel 4: Failed to open stream: Permission denied

laravellaravel-4

提问by Bryan P

I'm having problem in setting up Laravel 4. I'm having this error when opening the index page:

我在设置 Laravel 4 时遇到问题。打开索引页面时出现此错误:

file_put_contents(/Users/laravel/app/storage/meta/services.json) [function.file-put-contents]:
failed to open stream: Permission denied.

file_put_contents(/Users/laravel/app/storage/meta/services.json) [function.file-put-contents]:
无法打开流:权限被拒绝。

What am I missing here?

我在这里缺少什么?

回答by Fran?ois

I think chmod -777 is a bad practice.

我认为 chmod -777 是一种不好的做法。

To solve permissions issue on Laravel, I've done this (with root user):

为了解决 Laravel 上的权限问题,我已经这样做了(使用 root 用户):

cd app/

cd app/

chown -R www-data:www-data storage

chown -R www-data:www-data storage

cd storage/

cd storage/

find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \;

find . -type d -exec chmod 775 {} \; && find . -type f -exec chmod 664 {} \;

And always in app/storage directory :

并且始终在 app/storage 目录中:

chown your_user:user_group .gitignore cache/.gitignore logs/.gitignore meta/.gitignore sessions/.gitignore views/.gitignore

chown your_user:user_group .gitignore cache/.gitignore logs/.gitignore meta/.gitignore sessions/.gitignore views/.gitignore

Now, exit the root user, and it's ok.

现在,退出root用户,就OK了。

EDIT : this was for Laravel4. This doesn't works for Laravel5 because of a different structure.

编辑:这是针对 Laravel4 的。由于结构不同,这不适用于 Laravel5。

回答by Franz

The storagedirectory needs to be writable by the webserver user.

storage目录需要可由网络服务器用户写入。

回答by Bryan P

It's better that you do not change the permissions, you should just change the owner:groupof the storage folder to that of the owner:groupof apache by using chown, this is more complicated but is more secure and you'll get used to this soon, you can find this in the httpd.conf

最好不要更改权限,您应该owner:group使用 将存储文件夹的文件夹更改owner:group为 apache 的文件夹chown,这更复杂但更安全,您很快就会习惯,您可以找到这个在httpd.conf 中

MAMP:

MAMP:

/Applications/MAMP/conf/apache/httpd.conf

XAMMP:

XAMMP:

/Applications/XAMPP/xamppfiles/etc/httpd.conf

Open the httpd.conf with your preferred editor then search for User/Group. After searching you will see these lines below that highlighted line you searched:

使用您喜欢的编辑器打开 httpd.conf,然后搜索User/Group. 搜索后,您将在搜索的突出显示行下方看到这些行:

User someuser
Group somegroup

Once you already know the User and Group, cd to your laravel directory then, do the chown:

一旦你已经知道用户和组,cd 到你的 laravel 目录,然后执行chown

chown -R someuser:somegroup app/storage

P.S: If you get permission something error upon doing chown, try this:

PS:如果你在做的时候得到了一些错误的许可chown,试试这个:

sudo chown -R someuser:somegroup app/storage

It will then ask for your password so input it then done.

然后它会询问你的密码,所以输入它然后完成。

回答by user3670777

Just ran into this problem on centos 7. The blocker wasn't folder permissions, rather it was selinux policy blocking nginx/php to access /var/www. So, if the above doesn't work, try disabling selinux as a test to see if you can re-run composer without any permission issues.

刚刚在centos 7 上遇到了这个问题。阻止程序不是文件夹权限,而是阻止nginx/php 访问/var/www 的selinux 策略。因此,如果上述方法不起作用,请尝试禁用 selinux 作为测试,看看您是否可以在没有任何权限问题的情况下重新运行 composer。

回答by Ajnas Kt

If you are using Apache on Ubuntu, storage and bootstrap/cache folders need to be writable by web server user.

如果您在 Ubuntu 上使用 Apache,则 web 服务器用户需要可写入存储和引导程序/缓存文件夹。

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

This will allow write permissions to these folders for web server users.

这将允许 Web 服务器用户对这些文件夹的写入权限。

回答by ivahidmontazer

In my case this error was thrown:

在我的情况下,这个错误被抛出:

fopen(php://stdout): failed to open stream: operation failed

fopen(php://stdout): 无法打开流:操作失败

i am using a virtual host in Wamp. therefor i added this line to my <VirtualHost>-> <Directory>block in httpd-vhosts.conffile:

我在 Wamp 中使用虚拟主机。因此,我将此行添加到我的<VirtualHost>->文件<Directory>块中httpd-vhosts.conf

Require all granted

and my block is:

我的块是:

<VirtualHost *:80>
    ServerName laravel
    DocumentRoot d:/wamp/www
    <Directory  "d:/wamp/www/">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

then problem solved!

然后问题解决了!