How to set up file permissions for Laravel?

前端 未结 15 2159
忘了有多久
忘了有多久 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:39

    The Laravel 5.4 docs say:

    After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.

    There are a lot of answers on this page that mention using 777 permissions. Don't do that. You'd be exposing yourself to hackers.

    Instead, follow the suggestions by others about how to set permissions of 755 (or more restrictive). You may need to figure out which user your app is running as by running whoami in the terminal and then change ownership of certain directories using chown -R.

    If you do not have permission to use sudo as so many other answers require...

    Your server is probably a shared host such as Cloudways.

    (In my case, I had cloned my Laravel application into a second Cloudways server of mine, and it wasn't completely working because the permissions of the storage and bootstrap/cache directories were messed up.)

    I needed to use:

    Cloudways Platform > Server > Application Settings > Reset Permission

    Then I could run php artisan cache:clear in the terminal.

提交回复
热议问题