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

前端 未结 7 1646
后悔当初
后悔当初 2021-01-31 00:19

To stop you from the start, there is NO permission issue. /storage is recursively chmodded 777 and whole project folder is chowned by apache:apache

I even r

7条回答
  •  不知归路
    2021-01-31 00:37

    It could be that SElinux is preventing Apache from creating 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 disabling SElinux. I know it is not the right thing to do but I haven'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 have just updated 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//storage(/.*)?"
      
      semanage fcontext -a -t httpd_sys_rw_content_t "/var/www//bootstrap/cache(/.*)?"
      
    2. The SELinux context needs to be applied on the directories:

      restorecon -Rv "/var/www//storage"
      
      restorecon -Rv "/var/www//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 to enable SELinux again.

提交回复
热议问题