#!/bin/sh

echo "Starting Laravel setup..."

cd /var/www

# Install dependencies
composer install --no-interaction --prefer-dist --optimize-autoloader
npm install
npm run build

# Setup Laravel app
cp .env.production .env
php artisan key:generate
php artisan storage:link
php artisan migrate:fresh --seed
php artisan app:regenerate-policies
php artisan serve --host=0.0.0.0 --port=8050

# Change ownership to avoid permission issues
chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache

# Start PHP-FPM
echo "🚀 Starting PHP-FPM..."
exec php-fpm
