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

3

我查看了一下,大部分答案都不适用于共享主机,而这恰好是我的情况。

我已经对 storagebootstrap/cache/ 进行了 chmod 775 的操作。我还有一个 storage/framework/views 目录,尝试过删除 storage/logs/laravel.log 文件。

需要注意的是,该脚本在我以前的共享主机计划中运行良好,只有包含 file_get_contents 的页面出现了问题。

涉及到的文件是 PostController.php 中的 ErrorException,位于第 17 行:我在使用 file_get_contents 调用。


哪个文件被拒绝访问权限?通常这个错误会包含文件路径。 - Devon Bessemer
这是一个错误异常,位于PostController.php文件的第17行。 - tagni hugues pascal
我想象你的共享托管提供商禁用了file_get_contents函数。相关链接:https://dev59.com/_lPTa4cB1Zd3GeqPh0l_ - Scopey
可能是file_get_contents()的等效函数吗?的重复问题。 - Scopey
@tagnihuguespascal 在你遇到错误的地方添加你的 PostController 代码。 - Nikhil Radadiya
展示你的 PostController - Nauman Zafar
3个回答

4

在 CentOS 7 + Apache 上:

cd /var/www/laravelfolder
sudo chown apache:apache -R /var/www/laravelfolder
find . -type f -exec chmod 0644 {} \;
find . -type d -exec chmod 0755 {} \;
sudo chcon -t httpd_sys_content_t /var/www/laravelfolder -R
sudo chcon -t httpd_sys_rw_content_t /var/www/laravelfolder/storage -R
sudo chcon -t httpd_sys_rw_content_t /var/www/laravelfolder/bootstrap/cache -R

来源:https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

当使用CentOS 7、SELinux、Apache和PHP时,即使拥有正确的权限,也可能无法写入或访问文件。这是由于SELinux策略限制了Apache进程对文件系统的访问。可以通过以下命令解决该问题:
1. 安装SELinux命令行工具:yum install policycoreutils-python 2. 查找被拒绝的SELinux访问:grep httpd /var/log/audit/audit.log | audit2allow -M mypol 3. 启用新策略模块:semodule -i mypol.pp

这对我来说是一个很好的解决方案,因为我一直在尝试追踪“Permission denied”错误,而那些文件已经存在于我的系统上,并且我认为权限设置是正确的。 - hemisphire

3

尝试运行

php artisan config:cache

然后再运行

php artisan env


0

我觉得你设置了错误的权限。给bootstrap\cache和storage目录分别设置777权限,而不是775权限。请点击这里查看。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接