Laravel File Permission in Ubuntu Server
I found that there is a lot of developer have issues which files/folders permission when setup a project in staging/production server.
Here is where i solved every time i faced permission issues.
After composer install
,
- Most important, need to make sure the storage folder and bootstrap/cache is in proper permission. The application directory is owned by our system user and is readable but not writable by the web server. It’s correct but there are few directories that need special treatment. Let’s change the group ownership of the
storage
andbootstrap/cache
directories to www-data.
# sudo chgrp -R www-data storage bootstrap/cache
# sudo chmod -R ug+rwx storage bootstrap/cache
2. Make sure all the files in 664 or 644 and 775 or 755 for folders. In my case :-
# sudo find project_folder -type f -exec chmod 664 {} \;
# sudo find project_folder -type d -exec chmod 775 {} \;
I see a lot of developer recommend other developer to use 777 🤷♂️. Don’t they know 777 is dangerous move. Refer here.
3. There is a case that your application can’t write/read your logs file. But first, delete everything inside logs folder
# sudo chmod g+s storage/logs/
# sudo setfacl -d -m g::rwx storage/logs/
This will inherit the permission from the parent folder
This helps me every time. Hope its help 😁