#!/bin/bash # Laravel Server Setup Script echo "===================================" echo "Laravel Server Setup" echo "===================================" # Navigate to project directory cd /var/www/html/New-Thanasoft/thanasoft-back # Enable Apache mod_rewrite echo "Enabling mod_rewrite..." sudo a2enmod rewrite # Set proper permissions echo "Setting permissions..." sudo chown -R www-data:www-data /var/www/html/New-Thanasoft/thanasoft-back sudo chmod -R 775 storage bootstrap/cache # Clear all caches echo "Clearing caches..." php artisan route:clear php artisan cache:clear php artisan config:clear php artisan view:clear # Cache routes for production echo "Caching routes..." php artisan route:cache php artisan config:cache # Check .htaccess exists echo "Checking .htaccess..." if [ -f public/.htaccess ]; then echo "✓ .htaccess exists" else echo "✗ .htaccess NOT found - copying from framework..." cat > public/.htaccess << 'EOF' Options -MultiViews -Indexes RewriteEngine On # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # 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] EOF echo "✓ .htaccess created" fi # Restart Apache echo "Restarting Apache..." sudo systemctl restart apache2 echo "" echo "===================================" echo "Setup Complete!" echo "===================================" echo "" echo "Testing API endpoint..." curl -I http://78.138.58.60/api/auth/login echo "" echo "Check Apache error logs with:" echo "sudo tail -f /var/log/apache2/thanasoft_error.log"