事实上,我是laravel的新手,我正在尝试创建我的第一个项目。出于某种原因,我一直得到这个错误(我甚至还没有开始编码)

Error in exception handler: The stream or file "/var/www/laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/laravel/bootstrap/compiled.php:8423

我读到这与权限有关,但chmod -R 775存储根本没有帮助。


当前回答

我在这个问题上尝试了不同的命令,但这些将有助于解决问题

php artisan route:clear
php artisan config:clear
php artisan cache:clear

希望这也能帮助到其他人。

其他回答

试试这个

cd /var/www/html setenforce 0 服务HTTPD重启

对于所有在Laravel环境下的Centos 7用户,不需要禁用Selinux,只需要运行这些命令:

yum install policycoreutils-python -y # might not be necessary, try the below first

semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/laravel/storage(/.*)?" # add a new httpd read write content to sellinux for the specific folder, -m for modify
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/laravel/bootstrap/cache(/.*)?" # same as the above for b/cache

restorecon -Rv /var/www/html/ # this command is very important to, it's like a restart to apply the new rules

最后,确保您的主机、ip和虚拟主机都正确用于远程访问。

Selinux的目的是限制对根用户的访问,所以只有必要的东西可以访问,至少从一般的概述来看,它是额外的安全,禁用它不是一个好的实践,有许多学习Selinux的链接,但在这种情况下甚至不需要它。

最大的人建议更改文件权限777或775,我认为这不是一个合适的方法来解决这个问题。您只需要更改存储和引导文件夹的所有权。

在下面的图片中,你可以看到我所有的文件/文件夹都在根用户下(除了存储和引导,因为我改变了所有权),但我是以管理员身份登录的(在改变所有权之前),这就是为什么它总是给予拒绝权限的原因。所以我需要把这两个文件夹的所有权改为管理员

我是怎么做的呢, 转到项目目录并运行以下命令。 sudo chown -R yourusername:www-data storage sudo chmod -R ug+w storage, sudo chown -R yourusername:www-data bootstrap, sudo chmod -R ug+w bootstrap

只需在项目根目录-中运行以下命令

sudo chmod -R 775 storage
sudo chown -R $USER:www-data storage

这是我在运行Apache时所做的:

sudo chown -R $USER:www-data my_laravel_project/

sudo chmod -R 775 my_laravel_project/storage

sudo chmod -R 775 my_laravel_project/bootstrap/cache

cd my_laravel_project

php artisan optimize:clear