正确的laravel存储权限 [英] Proper laravel storage permissions

查看:781
本文介绍了正确的laravel存储权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将本地laravel 5存储文件夹设置为权限755和用户www-data,因为我在计算机上使用apache2.但是,我得到的是空白屏幕,而不是错误的堆栈跟踪记录,因此我将权限更改为777,从而解决了该问题.

I have set my local laravel 5 storage folder to permissions 755 and to user www-data, as I use apache2 on my machine. However I was getting blank screens instead of stack traces on errors so I changed the permissions to 777 which resolved the issue.

但是我觉得这是一个(可怕的)创可贴,因为实际上它允许任何用户使用所有权限而不是具有有限权限的正确用户来修改此目录.我不知道此问题是否会影响开发或生产服务器,但是在这种情况下授予这些权限不是一种选择.

However I feel this is a (terrible) bandaid as really it is allowing any user to modify this directory with all permissions rather than the correct user with limited permissions. I don't know if this issue will affect the development or production server but granting those permissions in such a scenario is not an option.

我如何确定哪个用户(或组)实际上需要使用该目录进行laravel日志记录的权限,以便我可以将目录分配给他们,然后将权限返回到755?

How do I figure out which user (or group) actually needs permissions to use this directory for laravel logging so I can assign the directory to them and return the permissions back to 755?

我尝试过

ps aux | egrep '(apache|httpd)'

但是它表明大多数进程都以www-data ...

but it shows that most processes are being run as www-data...

推荐答案

您在使用ps aux | egrep '(apache|httpd)'的正确轨道上.

You're on the right track with ps aux | egrep '(apache|httpd)'.

Apache/httpd以用户root的身份启动,但随后生成了以其配置中定义的用户身份处理传入请求的进程.该默认用户通常是www-dataapache.

Apache/httpd is started as user root, but then it spawns processes to handle incoming request as the user defined in it's configuration. That default user is usually either www-data or apache.

CentOS/RedHat 服务器上,您可能会看到以用户/组apache(默认)运行的进程.

On CentOS/RedHat servers, you'll likely see processes being run as user/group apache (this is the default).

Debian/Ubuntu 上,处理请求的进程的默认用户设置为www-data.

On Debian/Ubuntu, the default user set for the processes handling requests is www-data.

这全部假设apache正在使用mod-php .如果您使用的是php-fpm,则可以单独配置运行PHP的使用程序(根据我的经验,它的默认设置与apache相同).

This all assumes apache is using mod-php. If you are using php-fpm, the use running PHP may be configured separately (altho it has the same defaults as apache in my experience).

听起来您知道,storage目录需要由运行这些进程的用户或组(取决于权限)可写.

As it sounds like you know, the storage directory needs to be writable by the user or group (depending on permissions) running those processes.

听起来ps aux | egrep '(apache|httpd)'的结果为www-data,因此该目录可能需要由用户/组www-data写入(但可以将其设置为所有者和所有者),而不是100%明确确保所有者拥有这些权限,或者通过组权限进行设置,或者使其可全局写入.

It sounds like the result of ps aux | egrep '(apache|httpd)' was www-data, so it's likely, but not 100% definitive, that the directory needs to be writable by user/group www-data (either by setting it as the owner and ensuring owner has those permissions, or setting it via group permissions, or making it world-writable).

一种简单的判断方法是,是否从storage目录中删除日志文件/查看缓存文件,然后将该目录设置为可写.

One easy way to tell is if you delete the log file / view cache files from the storage directory, and then make that directory world-writable.

在Laravel中进行一些请求,以重新生成这些文件,然后查看在新文件上设置了哪些用户/组.

Make some requests in Laravel that would re-generate those files, and then see what user/group is set on the new files.

这是查看运行PHP的进程的用户/组设置的一种方式.

That is one way to see what the user/group is set to of the process running PHP.

这篇关于正确的laravel存储权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆