fix permision deploy
This commit is contained in:
85
debug-permissions.sh
Executable file
85
debug-permissions.sh
Executable file
@@ -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"
|
||||
23
deploy.sh
23
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"
|
||||
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!"
|
||||
73
fix-permissions.sh
Executable file
73
fix-permissions.sh
Executable file
@@ -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"
|
||||
Reference in New Issue
Block a user