l2t

How to set up file permissions for Laravel?

Asked: 4 months ago

I have been working on laravel for so long and found that most of the developers they stuck at setting permission for their laravel project properly.

In this question I would like to address on how you can properly set your laravel project permissions. Open your terminal window and head to your laravel project root directory and run following command to set proper folder permissions:

# Run following commands if you are using MacOS
 HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
 sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" storage
 sudo chmod +a "$(whoami) allow delete,write,append,file_inherit,directory_inherit" storage

 # Run following commands if you are using linux
 HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
 sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX storage
 sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX storage

I hope this would help solving your project permission issues.

Viewed: 128 times
Liked: 7 times