【发布时间】:2020-03-18 03:50:22
【问题描述】:
在生产服务器上进入我的站点时出现以下错误:
无法打开流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”:无法打开流:权限被拒绝
我尝试运行以下命令并在终端中拒绝权限:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
我运行了chmod -R 775 storage/logs/ 和composer dump-autoload,我能够毫无任何错误地进入我网站的主页。在网站上浏览了更多之后,我在各个领域都遇到了同样的错误,而在其他地方却没有:
又是同样的错误
无法打开流或文件“/var/app/current/storage/logs/laravel-2019-11-22.log”:无法打开流:权限被拒绝
我删除了以下文件并运行php artisan cahce:clear:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php
我看到的唯一其他建议是运行:
sudo chmod -R 777 storage/*
这在生产服务器上似乎是个坏主意,但似乎是赞成的答案。我应该只给我的存储主管 777 权限吗?为什么?还有另一种解决方法吗?
编辑:
我正在尝试按照此处所述执行此操作:
// set current user as owner and the webserver user as the group
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
// set directory permission to be 775
chmod -R 775 storage
chmod -R 775 bootstrap/cache
但是当我运行sudo chown -R $USER:www-data storage 时,我得到了这个错误:
chown: 无效组:'myusername:www-data'
【问题讨论】:
-
给目录775权限,给文件664权限
-
好的,
chmod -R 775 storage/logs/,您可以授予可能尚未创建的文件的权限吗?我不确定该怎么做? -
我说的是laravel中所有文件和文件夹的权限,你可以这样:
sudo find /path/to/your/laravel/root/directory -type f -exec chmod 664 {} \;sudo find /path/to/your/laravel/root/directory -type d -exec chmod 775 {} \; -
这些是我在安装 Laravel 项目后经常使用的命令,它们运行良好。从应用程序的根目录运行
sudo chown $USER:http ./storage -R然后sudo chown $USER:http ./bootstrap/cache -R然后find ./storage -type d -exec chmod 775 {} \;然后find ./storage -type f -exec chmod 664 {} \;然后find ./bootstrap/cache -type d -exec chmod 775 {} \; -
对不起,我昨天迟到了继续讨论。我检查了您提供的链接,从那里的内容来看,服务器的用户名是
apache,所以您可以尝试使用sudo chown $USER:apache ./storage -R,然后是find ./storage -type d -exec chmod 775 {} \;和find ./storage -type f -exec chmod 664 {} \;。我不确定 AWS 服务是否可以肯定地说出来,但总而言之,您必须找到服务器使用的用户名,并授予它对/storage和/bootstrap/cache目录和子目录的写入权限。
标签: laravel amazon-web-services amazon-ec2 permissions amazon-elastic-beanstalk