Skip to content

Instantly share code, notes, and snippets.

@thekavish
Last active October 1, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thekavish/00578028c77ba300d647d071c5fbfb78 to your computer and use it in GitHub Desktop.
Save thekavish/00578028c77ba300d647d071c5fbfb78 to your computer and use it in GitHub Desktop.
Set up file permissions for Laravel

How to set up file permissions for Laravel with current user as owner

I prefer to own all the directories and files (it makes working with everything much easier), so, go to your laravel root directory:

cd /var/www/html/laravel >> assuming this is your current root directory sudo chown -R $USER:www-data .

Then I give both myself and the webserver permissions:

sudo find . -type f -exec chmod 664 {} \;

sudo find . -type d -exec chmod 775 {} \;

Then give the webserver the rights to read and write to storage and cache

Whichever way you set it up, then you need to give read and write permissions to the webserver for storage, cache and any other directories the webserver needs to upload or write too (depending on your situation), so run the commands from bashy above :

sudo chgrp -R www-data storage bootstrap/cache

sudo chmod -R ug+rwx storage bootstrap/cache

Now, you're secure and your website works, AND you can work with the files fairly easily

(Answer found on https://stackoverflow.com/questions/30639174/how-to-set-up-file-permissions-for-laravel#answer-37266353)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment