#!/bin/bash # Script untuk fix permissions Laravel setelah deployment # Jalankan di server production PROJECT_PATH=${1:-"/var/www/pupr"} echo "๐Ÿ”ง Fixing Laravel permissions for: $PROJECT_PATH" # Check if path exists if [ ! -d "$PROJECT_PATH" ]; then echo "โŒ Project path not found: $PROJECT_PATH" echo "Usage: ./fix-permissions.sh /path/to/your/project" exit 1 fi cd "$PROJECT_PATH" echo "๐Ÿ“ Setting correct ownership..." # Set ownership to web server user sudo chown -R www-data:www-data . echo "๐Ÿ“‚ Setting directory permissions..." # Set directory permissions sudo find . -type d -exec chmod 755 {} \; echo "๐Ÿ“„ Setting file permissions..." # Set file permissions sudo find . -type f -exec chmod 644 {} \; echo "๐Ÿ” Setting special permissions for Laravel..." # Storage and cache directories need write permissions sudo chmod -R 775 storage/ sudo chmod -R 775 bootstrap/cache/ # Make sure these directories exist sudo mkdir -p storage/framework/views sudo mkdir -p storage/framework/cache sudo mkdir -p storage/framework/sessions sudo mkdir -p storage/logs sudo mkdir -p storage/app/public # Set ownership for storage and bootstrap/cache sudo chown -R www-data:www-data storage/ sudo chown -R www-data:www-data bootstrap/cache/ echo "๐Ÿ”‘ Setting executable permissions for Artisan..." sudo chmod +x artisan echo "๐Ÿงน Clearing Laravel caches..." # Clear all caches php artisan config:clear php artisan route:clear php artisan view:clear php artisan cache:clear # Recreate caches with correct permissions php artisan config:cache php artisan route:cache php artisan view:cache echo "๐Ÿ“‹ Checking permissions..." echo "Storage permissions:" ls -la storage/ echo "" echo "Framework permissions:" ls -la storage/framework/ echo "" echo "โœ… Permissions fixed successfully!" echo "๐Ÿ’ก If you still get permission errors, also run:" echo " sudo setsebool -P httpd_can_network_connect on" echo " sudo setsebool -P httpd_unified on"