#!/bin/bash # Debug script untuk diagnosa permission issues # Jalankan di server untuk check masalah permission PROJECT_PATH=${1:-"/var/www/pupr"} echo "๐Ÿ” Debugging permissions for: $PROJECT_PATH" echo "=================================================" # Check if path exists if [ ! -d "$PROJECT_PATH" ]; then echo "โŒ Project path not found: $PROJECT_PATH" exit 1 fi cd "$PROJECT_PATH" echo "๐Ÿ“Š Current User & Groups:" echo "Current user: $(whoami)" echo "Web server user: $(ps aux | grep -E 'apache|nginx|httpd' | grep -v grep | head -1 | awk '{print $1}')" echo "" echo "๐Ÿ“ Directory Ownership & Permissions:" echo "Project root:" ls -la . | head -5 echo "" echo "Storage directory:" ls -la storage/ echo "" echo "Storage/framework:" ls -la storage/framework/ 2>/dev/null || echo "storage/framework/ not found" echo "" echo "Bootstrap/cache:" ls -la bootstrap/cache/ 2>/dev/null || echo "bootstrap/cache/ not found" echo "" echo "๐Ÿ” Permission Analysis:" # Check critical directories directories=("storage" "storage/framework" "storage/framework/views" "storage/framework/cache" "storage/logs" "bootstrap/cache") for dir in "${directories[@]}"; do if [ -d "$dir" ]; then perm=$(stat -c "%a" "$dir") owner=$(stat -c "%U:%G" "$dir") echo "โœ… $dir: $perm ($owner)" else echo "โŒ $dir: NOT FOUND" fi done echo "" echo "๐Ÿงช Write Test:" # Test write permissions if [ -w "storage/framework/" ]; then echo "โœ… storage/framework/ is writable" # Try creating a test file if touch storage/framework/test_write_$(date +%s).tmp 2>/dev/null; then echo "โœ… Can create files in storage/framework/" rm -f storage/framework/test_write_*.tmp else echo "โŒ Cannot create files in storage/framework/" fi else echo "โŒ storage/framework/ is NOT writable" fi echo "" echo "โš™๏ธ SELinux Status (if applicable):" if command -v getenforce &> /dev/null; then echo "SELinux: $(getenforce)" if [ "$(getenforce)" = "Enforcing" ]; then echo "โš ๏ธ SELinux is enforcing - may need additional configuration" echo "Try: sudo setsebool -P httpd_unified on" fi else echo "SELinux not installed" fi echo "" echo "๐Ÿ“‹ Recommended Actions:" echo "1. Fix ownership: sudo chown -R www-data:www-data $PROJECT_PATH" echo "2. Fix permissions: sudo chmod -R 775 $PROJECT_PATH/storage/" echo "3. Clear cache: php artisan view:clear" echo "4. If SELinux: sudo setsebool -P httpd_unified on"