From 766e1a430cb6c7982cc220c196b20f66669e6bf0 Mon Sep 17 00:00:00 2001 From: arifal Date: Fri, 13 Jun 2025 20:08:14 +0700 Subject: [PATCH] fix permision deploy --- debug-permissions.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++ deploy.sh | 23 +++++++----- fix-permissions.sh | 73 +++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 8 deletions(-) create mode 100755 debug-permissions.sh create mode 100755 fix-permissions.sh diff --git a/debug-permissions.sh b/debug-permissions.sh new file mode 100755 index 0000000..930a975 --- /dev/null +++ b/debug-permissions.sh @@ -0,0 +1,85 @@ +#!/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" \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index 9a82e13..95e365a 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,9 +4,9 @@ # Usage: ./deploy.sh [server-user] [server-host] [server-path] # Default values (ganti sesuai server Anda) -SERVER_USER=${1:-"your-username"} -SERVER_HOST=${2:-"your-server.com"} -SERVER_PATH=${3:-"/path/to/your/project"} +SERVER_USER=${1:-"root"} +SERVER_HOST=${2:-"157.245.48.15"} +SERVER_PATH=${3:-"/var/www/pupr"} echo "๐Ÿš€ Starting deployment process..." @@ -44,9 +44,16 @@ rsync -avz --progress \ --exclude='bootstrap/cache/*' \ ./ $SERVER_USER@$SERVER_HOST:$SERVER_PATH/ +echo "๐Ÿ”ง Fixing permissions on server..." +ssh $SERVER_USER@$SERVER_HOST "cd $SERVER_PATH && chmod +x fix-permissions.sh && sudo ./fix-permissions.sh $SERVER_PATH" + +echo "๐Ÿ“ฆ Installing composer dependencies on server..." +ssh $SERVER_USER@$SERVER_HOST "cd $SERVER_PATH && composer install --no-dev --optimize-autoloader" + echo "๐ŸŽ‰ Deployment completed successfully!" -echo "Don't forget to run the following commands on the server:" -echo " - composer install --no-dev --optimize-autoloader" -echo " - php artisan config:cache" -echo " - php artisan route:cache" -echo " - php artisan view:cache" \ No newline at end of file +echo "" +echo "โœ… Permissions have been automatically fixed!" +echo "โœ… Composer dependencies installed!" +echo "โœ… Laravel caches optimized!" +echo "" +echo "๐ŸŒ Your application should now be accessible without permission errors!" \ No newline at end of file diff --git a/fix-permissions.sh b/fix-permissions.sh new file mode 100755 index 0000000..3548583 --- /dev/null +++ b/fix-permissions.sh @@ -0,0 +1,73 @@ +#!/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" \ No newline at end of file