Files
sibedas/fix-permissions.sh
2025-06-13 20:08:14 +07:00

73 lines
1.9 KiB
Bash
Executable File

#!/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"