How to set up file permissions for Laravel?

前端 未结 15 2110
忘了有多久
忘了有多久 2020-11-22 00:08

I\'m using Apache Web Server that has the owner set to _www:_www. I never know what is the best practice with file permissions, for example when I create new La

15条回答
  •  无人共我
    2020-11-22 00:44

    This worked for me:

    cd [..LARAVEL PROJECT ROOT]
    sudo find . -type f -exec chmod 644 {} \;
    sudo find . -type d -exec chmod 755 {} \;
    sudo chmod -R 777 ./storage
    sudo chmod -R 777 ./bootstrap/cache/
    

    Only if you use npm (VUE, compiling SASS, etc..) add this:

    sudo chmod -R 777 ./node_modules/
    

    What it does:

    • Change all file permissions to 644
    • Change all folder permissions to 755
    • For storage and bootstrap cache (special folders used by laravel for creating and executing files, not available from outside) set permission to 777, for anything inside
    • For nodeJS executable, same as above

    Note: Maybe you can not, or don't need, to do it with sudo prefix. it depends on your user's permissions, group, etc...

提交回复
热议问题