2026-03-16 10:20:15 +07:00
|
|
|
#!/bin/sh
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
echo "========================================"
|
|
|
|
|
echo "Starting container setup..."
|
|
|
|
|
echo "========================================"
|
|
|
|
|
|
2026-03-23 11:27:36 +07:00
|
|
|
# Show current user and directory
|
2026-03-16 10:20:15 +07:00
|
|
|
echo "Current user: $(whoami)"
|
|
|
|
|
echo "Current directory: $(pwd)"
|
|
|
|
|
|
2026-03-29 19:35:21 +07:00
|
|
|
# Force debug mode for troubleshooting
|
|
|
|
|
export APP_DEBUG=true
|
|
|
|
|
export LOG_LEVEL=debug
|
|
|
|
|
|
2026-03-23 11:44:37 +07:00
|
|
|
# Create ALL required Laravel directories
|
|
|
|
|
echo "Creating storage directories..."
|
|
|
|
|
mkdir -p storage/framework/cache
|
|
|
|
|
mkdir -p storage/framework/sessions
|
|
|
|
|
mkdir -p storage/framework/views
|
|
|
|
|
mkdir -p storage/framework/testing
|
2026-03-23 11:27:36 +07:00
|
|
|
mkdir -p storage/logs
|
|
|
|
|
mkdir -p bootstrap/cache
|
2026-03-16 10:20:15 +07:00
|
|
|
|
2026-03-23 11:44:37 +07:00
|
|
|
# Also create the view cache directory (sometimes needed)
|
|
|
|
|
mkdir -p storage/framework/views
|
|
|
|
|
|
2026-03-16 10:20:15 +07:00
|
|
|
# Set permissions
|
|
|
|
|
echo "Setting permissions..."
|
2026-03-23 11:27:36 +07:00
|
|
|
chmod -R 777 storage
|
|
|
|
|
chmod -R 777 bootstrap/cache
|
2026-03-16 10:20:15 +07:00
|
|
|
|
2026-03-23 11:44:37 +07:00
|
|
|
# Create cache file if it doesn't exist
|
|
|
|
|
touch storage/framework/cache/.gitignore
|
|
|
|
|
touch storage/framework/sessions/.gitignore
|
|
|
|
|
touch storage/framework/views/.gitignore
|
|
|
|
|
touch storage/logs/.gitignore
|
|
|
|
|
|
|
|
|
|
# Verify directories exist
|
|
|
|
|
echo "Verifying directories..."
|
|
|
|
|
ls -la storage/framework/
|
|
|
|
|
ls -la bootstrap/
|
|
|
|
|
|
2026-03-23 11:27:36 +07:00
|
|
|
# Check if .env exists, create if not
|
2026-03-16 10:20:15 +07:00
|
|
|
if [ ! -f .env ]; then
|
2026-03-23 11:27:36 +07:00
|
|
|
echo "Creating .env file..."
|
|
|
|
|
if [ -f .env.example ]; then
|
|
|
|
|
cp .env.example .env
|
|
|
|
|
else
|
2026-03-23 11:44:37 +07:00
|
|
|
cat > .env << 'EOF'
|
|
|
|
|
APP_NAME=Laravel
|
|
|
|
|
APP_ENV=local
|
|
|
|
|
APP_KEY=
|
|
|
|
|
APP_DEBUG=true
|
|
|
|
|
APP_URL=http://localhost
|
|
|
|
|
LOG_CHANNEL=stack
|
|
|
|
|
EOF
|
2026-03-23 11:27:36 +07:00
|
|
|
fi
|
2026-03-16 10:20:15 +07:00
|
|
|
fi
|
|
|
|
|
|
2026-03-29 19:35:21 +07:00
|
|
|
# Generate key if not present (only if APP_KEY is empty or missing)
|
|
|
|
|
echo "Checking .env for APP_KEY..."
|
|
|
|
|
if ! grep -E "APP_KEY=.{10,}" .env; then
|
|
|
|
|
echo "APP_KEY is empty or missing. Generating..."
|
2026-03-23 11:44:37 +07:00
|
|
|
echo "Generating application key..."
|
2026-03-29 19:35:21 +07:00
|
|
|
# If the file doesn't have APP_KEY= at all, add it so artisan can replace it
|
|
|
|
|
if ! grep -q "APP_KEY=" .env; then
|
|
|
|
|
echo "Appending APP_KEY= placeholder..."
|
|
|
|
|
echo "" >> .env
|
|
|
|
|
echo "APP_KEY=" >> .env
|
|
|
|
|
fi
|
|
|
|
|
php artisan key:generate --no-interaction --force || echo "❌ Key generation failed!"
|
2026-03-23 11:44:37 +07:00
|
|
|
fi
|
|
|
|
|
|
2026-03-29 19:35:21 +07:00
|
|
|
echo "Verifying APP_KEY after generation:"
|
|
|
|
|
grep "APP_KEY" .env
|
|
|
|
|
|
2026-03-30 14:18:41 +07:00
|
|
|
# Ensure vendor directory matches composer.lock exactly, syncing missing packages
|
|
|
|
|
echo "Verifying and synchronizing Composer dependencies..."
|
2026-03-30 17:50:31 +07:00
|
|
|
# Run composer install to physically ensure all files (like laravel/prompts) are present in the volume
|
|
|
|
|
composer install --no-interaction --optimize-autoloader
|
|
|
|
|
|
|
|
|
|
# FIX: Ensure all generated/downloaded files are fully readable and executable by PHP-FPM
|
|
|
|
|
echo "Setting correct ownership for web server..."
|
|
|
|
|
chown -R www-data:www-data vendor
|
|
|
|
|
chmod -R 755 vendor
|
2026-03-29 19:35:21 +07:00
|
|
|
|
|
|
|
|
# Verify vendor integrity at PHP level
|
|
|
|
|
echo "Checking vendor visibility and READABILITY for PHP..."
|
|
|
|
|
ls -la /var/www/html/vendor/laravel/prompts/src/helpers.php
|
|
|
|
|
php -r 'if (file_exists("/var/www/html/vendor/laravel/prompts/src/helpers.php")) { echo "✅ file_exists true\n"; }'
|
|
|
|
|
php -r 'require "/var/www/html/vendor/laravel/prompts/src/helpers.php"; echo "✅ PHP successfully REQUIRED helpers.php\n";'
|
|
|
|
|
|
2026-03-23 11:44:37 +07:00
|
|
|
# Clear all caches to ensure fresh state
|
|
|
|
|
echo "Clearing caches..."
|
|
|
|
|
php artisan config:clear || true
|
|
|
|
|
php artisan cache:clear || true
|
|
|
|
|
php artisan view:clear || true
|
|
|
|
|
php artisan route:clear || true
|
|
|
|
|
|
2026-03-29 13:48:35 +07:00
|
|
|
# Verify Vite manifest exists
|
|
|
|
|
if [ -f public/build/manifest.json ]; then
|
|
|
|
|
echo "✅ Vite manifest found at public/build/manifest.json"
|
|
|
|
|
else
|
|
|
|
|
echo "⚠️ Warning: Vite manifest not found! Assets may not load correctly."
|
|
|
|
|
echo "Current contents of public/build:"
|
|
|
|
|
ls -la public/build/ 2>/dev/null || echo "public/build directory does not exist"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-23 11:44:37 +07:00
|
|
|
# Optional: Run migrations if needed
|
2026-03-23 11:27:36 +07:00
|
|
|
# php artisan migrate --force
|
2026-03-16 10:20:15 +07:00
|
|
|
|
|
|
|
|
echo "========================================"
|
|
|
|
|
echo "Setup complete. Starting application..."
|
|
|
|
|
echo "========================================"
|
|
|
|
|
|
2026-03-28 19:30:40 +07:00
|
|
|
# Start the application with proper error handling
|
2026-03-29 05:26:32 +07:00
|
|
|
if [ "$MODE" = "staging" ]; then
|
2026-03-29 19:35:21 +07:00
|
|
|
echo "Starting DIRECT PHP server on port 8000 (Bypassing artisan serve)..."
|
|
|
|
|
# Use direct php -S to eliminate any artisan wrapper issues
|
|
|
|
|
exec php -d opcache.enable=0 -S 0.0.0.0:8000 -t public server.php 2>&1 | tee -a /var/log/php-server.log
|
2026-03-16 10:20:15 +07:00
|
|
|
else
|
|
|
|
|
echo "Starting PHP-FPM on port 9000..."
|
2026-03-28 19:30:40 +07:00
|
|
|
# Ensure PHP-FPM is properly configured
|
|
|
|
|
exec php-fpm -F
|
2026-03-16 10:20:15 +07:00
|
|
|
fi
|