Fix laravel folders and files permissions. Also configurates webserver user group
#!/bin/bash
echo "Hello, "$USER". This script will configurate your laravel file and folder permissions"
echo "You should run this script with sudo! Please ctr+c if you are not running this script with sudo"
echo "Enter web server user [ENTER]: "
read name
echo "You have selected user: $name"
echo "Enter laravel main path [ENTER]: "
read path
echo "You have selected path: $path"
echo "Please double check the input! Press n to cencel or y to agree and press [ENTER]"
read input
if [ "$input" != "y" ]; then
echo "Exiting script..."
exit 0
fi
echo "Running: sudo chown -R $name:$name $path/"
sudo chown -R "$name":"$name" "$path"/
echo "Done!"
echo "Running: sudo usermod -a -G $name root"
sudo usermod -a -G "$name" root
echo "Done!"
echo "Running: sudo find $path -type f -exec chmod 644 {} \;"
sudo find "$path" -type f -exec chmod 644 {} \;
echo "Done!"
echo "Running: sudo find $path -type d -exec chmod 755 {} \;"
sudo find "$path" -type d -exec chmod 755 {} \;
echo "Done!"
echo "Running: sudo chown -R $name:$name $path"
sudo chown -R "$name":"$name" "$path"
echo "Done!"
echo "Running: sudo find $path -type f -exec chmod 664 {} \;"
sudo find "$path" -type f -exec chmod 664 {} \;
echo "Done!"
echo "Running: sudo find $path -type d -exec chmod 775 {} \;"
sudo find "$path" -type d -exec chmod 775 {} \;
echo "Done!"
echo "Running: sudo chgrp -R $name storage bootstrap/cache"
sudo chgrp -R "$name" "$path"/storage "$path"/bootstrap/cache
echo "Done!"
echo "Running: sudo chmod -R ug+rwx storage bootstrap/cache"
sudo chmod -R ug+rwx "$path"/storage "$path"/bootstrap/cache
echo "Done!"
echo "Laravel folder & files permissions fixed successfuly!"