#!/bin/sh set -e echo "========================================" echo "Starting container setup..." echo "========================================" # Show current user echo "Current user: $(whoami)" echo "Current directory: $(pwd)" # Create directories one by one with error checking echo "Creating storage directories..." mkdir -p storage/framework/cache || { echo "Failed to create cache dir"; exit 1; } mkdir -p storage/framework/sessions || { echo "Failed to create sessions dir"; exit 1; } mkdir -p storage/framework/views || { echo "Failed to create views dir"; exit 1; } mkdir -p storage/logs || { echo "Failed to create logs dir"; exit 1; } mkdir -p bootstrap/cache || { echo "Failed to create bootstrap cache dir"; exit 1; } # Set permissions echo "Setting permissions..." chmod -R 777 storage || { echo "Failed to set storage permissions"; exit 1; } chmod -R 777 bootstrap/cache || { echo "Failed to set bootstrap permissions"; exit 1; } # Verify directories echo "Verifying directories..." ls -la storage/framework/ ls -la bootstrap/ # Check if .env exists if [ ! -f .env ]; then echo "WARNING: .env file not found!" cp .env.example .env 2>/dev/null || echo "APP_ENV=production" > .env fi # Generate key echo "Generating application key..." php artisan key:generate --no-interaction --force || echo "Key generation failed" # Clear cache echo "Clearing cache..." php artisan config:clear || true php artisan cache:clear || true echo "========================================" echo "Setup complete. Starting application..." echo "========================================" # Start the application if [ "$MODE" = "dev" ]; then echo "Starting PHP built-in server on port 8000..." exec php artisan serve --host=0.0.0.0 --port=8000 else echo "Starting PHP-FPM on port 9000..." exec php-fpm fi