Laravel 5: laravel.log could not be opened: Permission Denied

我只是一个虾纸丫 提交于 2019-11-29 22:35:36

It could be that SElinux is preventing Apache to create this file.

To test this you could disable SElinux temporally with the following command:

setenforce 0

This will place SElinux in permissive mode. This means that you still receive an error message in your SElinux log file but SElinux will not block the command.

To activate SElinux again you can type:

setenforce 1

Or reboot your CentOS server.

Unfortunately I had also problems with Laravel 5 on CentOS and the cause was SElinux. I ended up with disabeling SElinux and I know it is not the right thing to do but I didn't had time to get the two working together yet!


Update

So I finally had sometime to investigate this further and I got SELinux working together with Laravel 5. I just update this post for people that might run into this issue cause disabling SELinux is not the best strategy as mentioned above.

Three things need to be done:

  1. The folders Storage and Bootstrap/Cache need to have the right SELinux context. This can be achieved via the following commands.

    semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/storage(/.*)?"
    
    semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/<Laravel Site>/bootstrap/cache(/.*)?"
    
  2. The SELinux context needs to be applied on the directories.

    restorecon -Rv "/var/www/<Laravel Site>/storage"
    
    restorecon -Rv "/var/www/<Laravel Site>/bootstrap/cache"
    
  3. The Apache user needs to have the rights to create files in both directories. This can be achieved via a ACL in CentOS 7.

    setfacl -R -m u:apache:rwX storage/
    
    setfacl -R -m u:apache:rwX bootstrap/cache/
    

The last thing you need to do is enabling SELinux again.

Try those commands for laravel 5

$ php artisan cache:clear 

$ sudo chmod -R 777 app/storage 

$ composer.phar dump-autoload

This happens because laravel do not have the permissions to write to the log file, at least for my case.

This worked for me, Laravel 5.4 and above

$ sudo chmod -R 755 storage/

$ sudo chown -R www-data storage/

$ sudo chgrp -R www-data storage/

$ php artisan cache:clear

$ php artisan config:cache

$ composer dumpautoload

Not all steps necessary.

You have to make sure the storage folder exists. If you're deploying from git, make sure the storage folder itself is tracked and created automatically.

ON Laravel 5.7

$ cd /var/www/html/ $ php artisan cache:clear Application cache cleared!

for centos 7

   # ausearch -c 'httpd' --raw | audit2allow -M my-httpd
   # semodule -i my-httpd.pp
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!