Skip to content

Instantly share code, notes, and snippets.

@khatriafaz
Last active April 10, 2021 18:51
Show Gist options
  • Save khatriafaz/65b43f83b1ea15ea742cfcd8a03ecf4f to your computer and use it in GitHub Desktop.
Save khatriafaz/65b43f83b1ea15ea742cfcd8a03ecf4f to your computer and use it in GitHub Desktop.
Laravel server file permissions
#!/bin/bash
# Default variables
apachename="${1:-apache}"
username="${2:-$USER}"
folder="${3:-.}"
# Change ownership to webserver user/group
chown -R $apachename:$apachename $folder
# Add user to webserver group
usermod -a -G $apachename $username
# Change ownership to normal user/ webserver group
chown -R $username:$apachename $folder
# Update permissions for all files
find $folder -type f -exec chmod 664 {} \;
# Update permissions for all folders
find $folder -type d -exec chmod 775 {} \;
# Change owner group to webserver group user for storage and bootrap cache folder
chgrp -R $apachename $folder/storage $folder/bootstrap/cache
# Change the permissions for storage and bootrap cache folder
chmod -R ug+rwx $folder/storage $folder/bootstrap/cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment