View file File name : VPS_DEPLOYMENT_FIX.md Content :# VPS Deployment - .htaccess Permission Fix Guide ## Issue You're seeing: "Forbidden - You don't have permission to access this resource. Server unable to read htaccess file, denying access to be safe" ## Solution ### Step 1: SSH into Your VPS ```bash ssh your_username@backup.alkashier.com # Or use: ssh -i /path/to/key.pem user@backup.alkashier.com ``` ### Step 2: Navigate to Project Root ```bash cd /path/to/your/alkashier_backup # Common paths: /home/username/public_html, /var/www/html, /home/username/domains/backup.alkashier.com, etc. ``` **To find the correct path:** ```bash pwd # Check current directory ls -la # List files - should see .env, artisan, public/ folder ``` ### Step 3: Fix File Permissions #### Option A: Standard Laravel Permissions ```bash # Fix directory permissions find . -type d -exec chmod 755 {} \; # Fix file permissions find . -type f -exec chmod 644 {} \; # Make .htaccess readable by Apache chmod 644 public/.htaccess # Ensure storage is writable chmod -R 775 storage chmod -R 775 bootstrap/cache # Ensure public directory is accessible chmod 755 public ``` #### Option B: More Restrictive (Recommended for Production) ```bash # Set owner and group (replace 'www-data' if your web user is different) sudo chown -R www-data:www-data . # Fix permissions chmod -R 755 . chmod -R 775 storage bootstrap/cache chmod 644 public/.htaccess chmod 644 public/index.php ``` ### Step 4: Verify mod_rewrite is Enabled ```bash # Check if Apache has mod_rewrite apache2ctl -M | grep rewrite # Should output: rewrite_module (shared) ``` If not enabled: ```bash sudo a2enmod rewrite sudo systemctl restart apache2 ``` ### Step 5: Check Apache Configuration Your Apache site configuration must allow .htaccess overrides. Check your VirtualHost configuration: ```bash # Find the configuration file sudo find /etc/apache2 -name "*.conf" | grep -E "(backup|site)" | head -5 # Or list available sites sudo ls /etc/apache2/sites-available/ ``` Edit your site configuration (likely `/etc/apache2/sites-available/backup.alkashier.com.conf`): ```bash sudo nano /etc/apache2/sites-available/your-site.conf ``` Ensure the VirtualHost section has: ```apache <VirtualHost *:80> ServerName backup.alkashier.com DocumentRoot /path/to/alkashier_backup/public <Directory /path/to/alkashier_backup/public> Options -MultiViews +FollowSymLinks AllowOverride All Require all granted </Directory> <Directory /path/to/alkashier_backup> AllowOverride None </Directory> </VirtualHost> ``` **Important**: Make sure `AllowOverride All` is set for the public directory. ### Step 6: Restart Apache ```bash sudo systemctl restart apache2 # Or sudo service apache2 restart ``` ### Step 7: Verify .htaccess Exists in public/ ```bash ls -la public/.htaccess # Should output: -rw-r--r-- 1 www-data www-data 740 ... ``` If it doesn't exist, create it: ```bash cat > public/.htaccess << 'EOF' <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews -Indexes </IfModule> RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # Handle X-XSRF-Token Header RewriteCond %{HTTP:x-xsrf-token} . RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}] # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> EOF ``` ### Step 8: Test the Fix ```bash # Test Apache configuration sudo apache2ctl configtest # Should output: Syntax OK ``` Visit your domain: `https://backup.alkashier.com` **If you still see the .htaccess error:** 1. Check Apache error log: ```bash sudo tail -50 /var/log/apache2/error.log ``` 2. Check if SELinux is blocking: ```bash getenforce # If it says 'Enforcing', you may need to adjust SELinux policies ``` 3. Check file ownership: ```bash ls -la public/.htaccess # Should show www-data or your web user as owner ``` ## Common Issues & Solutions ### Issue: "Invalid command" in .htaccess **Cause**: Apache directive not recognized **Solution**: Ensure mod_rewrite is enabled: `sudo a2enmod rewrite && sudo systemctl restart apache2` ### Issue: Still getting 403 Forbidden **Cause**: File permissions still wrong **Solution**: Run: `sudo chown -R www-data:www-data . && chmod -R 755 . && chmod -R 775 storage bootstrap/cache` ### Issue: Blank page or 500 error after fixing **Cause**: Laravel application error **Solution**: Check logs: `tail -100 storage/logs/laravel.log` ### Issue: Redirect loop on HTTPS **Cause**: .htaccess redirect conflict with web server **Solution**: Use Laravel's HTTPS detection in `.env`: `APP_URL=https://backup.alkashier.com` ## Next Steps After Fixing 1. **Test the application loads**: Visit `https://backup.alkashier.com` 2. **Configure production database**: Edit `.env` with your production database details 3. **Run migrations**: ```bash php artisan migrate ``` 4. **Set up cron job**: ```bash crontab -e # Add: * * * * * cd /path/to/alkashier_backup && php artisan schedule:run >> /dev/null 2>&1 ``` 5. **Update Google Cloud Console**: Make sure the OAuth redirect URI is set to `https://backup.alkashier.com/google-drive/callback` ## Testing Commands ```bash # Test database connection php artisan tinker >>> DB::connection()->getPdo(); >>> exit # List routes php artisan route:list # Check scheduled tasks php artisan schedule:list # Test backup command php artisan backups:run-scheduled ``` --- **Your application is ready to run. These fixes should resolve the .htaccess issue!**