Files
Laravel-Docker-Dev-Template/deploy/scripts/fix-permissions.sh
2026-03-06 08:57:05 +02:00

44 lines
1.0 KiB
Bash

#!/bin/bash
# Fix Laravel file permissions
# Usage: ./fix-permissions.sh /var/www/your-app
set -e
if [ -z "$1" ]; then
echo "Usage: $0 /path/to/laravel/app"
exit 1
fi
APP_PATH="$1"
if [ ! -d "$APP_PATH" ]; then
echo "Error: Directory $APP_PATH does not exist"
exit 1
fi
echo "Fixing permissions for: $APP_PATH"
# Set ownership
sudo chown -R www-data:www-data "$APP_PATH"
# Set directory permissions
sudo find "$APP_PATH" -type d -exec chmod 755 {} \;
# Set file permissions
sudo find "$APP_PATH" -type f -exec chmod 644 {} \;
# Make storage and cache writable
sudo chmod -R 775 "$APP_PATH/storage"
sudo chmod -R 775 "$APP_PATH/bootstrap/cache"
# Set ACL for current user to maintain access
if command -v setfacl &> /dev/null; then
sudo setfacl -Rm u:$(whoami):rwx "$APP_PATH/storage"
sudo setfacl -Rm u:$(whoami):rwx "$APP_PATH/bootstrap/cache"
sudo setfacl -dRm u:$(whoami):rwx "$APP_PATH/storage"
sudo setfacl -dRm u:$(whoami):rwx "$APP_PATH/bootstrap/cache"
fi
echo "Permissions fixed successfully!"