From 4398aee4497e5f5c7ced57b0a0ba0c54bf93f312 Mon Sep 17 00:00:00 2001 From: eko Date: Sat, 4 Apr 2026 23:34:45 +0700 Subject: [PATCH] fix production --- .gitea/workflows/pipeline.yml | 3 +- entrypoint.sh | 60 ++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/pipeline.yml b/.gitea/workflows/pipeline.yml index 96fe95df..1ba31e48 100644 --- a/.gitea/workflows/pipeline.yml +++ b/.gitea/workflows/pipeline.yml @@ -215,7 +215,7 @@ jobs: -e MODE=production \ -e APP_ENV=production \ -e APP_DEBUG=false \ - -e APP_URL=https://prod-test.kulakpos.id \ + -e AUTO_MIGRATE=false \ kode.sadateknologi.site/${{ gitea.repository_owner }}/kulakpos_web:$IMAGE_TAG # Wait for container to be ready @@ -261,6 +261,7 @@ jobs: -e MODE=production \ -e APP_ENV=production \ -e APP_DEBUG=false \ + -e AUTO_MIGRATE=false \ $PREVIOUS_IMAGE echo "Rollback completed" fi diff --git a/entrypoint.sh b/entrypoint.sh index 918e6e99..07dc358d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -9,9 +9,14 @@ echo "========================================" echo "Current user: $(whoami)" echo "Current directory: $(pwd)" -# Force debug mode for troubleshooting -export APP_DEBUG=true -export LOG_LEVEL=debug +# Set debug based on environment +if [ "$APP_ENV" = "production" ]; then + export APP_DEBUG=false + export LOG_LEVEL=error +else + export APP_DEBUG=true + export LOG_LEVEL=debug +fi # Create ALL required Laravel directories echo "Creating storage directories..." @@ -62,7 +67,6 @@ fi echo "Checking .env for APP_KEY..." if ! grep -E "APP_KEY=.{10,}" .env; then echo "APP_KEY is empty or missing. Generating..." - echo "Generating application key..." # 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..." @@ -80,7 +84,7 @@ echo "Verifying and synchronizing Composer dependencies..." # 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 +# FIX: Ensure all generated/downloaded files are fully readable and executable echo "Setting correct ownership for web server..." chown -R www-data:www-data vendor chmod -R 755 vendor @@ -91,13 +95,22 @@ 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";' -# Clear all caches to ensure fresh state -echo "Clearing caches..." -php artisan config:clear || true -php artisan view:clear || true -php artisan route:clear || true -php artisan cache:clear || true -php artisan optimize:clear || true +# Run production optimizations for production environment +if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then + echo "Running production optimizations..." + php artisan config:cache + php artisan route:cache + php artisan view:cache + php artisan event:cache +else + # Clear all caches to ensure fresh state for non-production + echo "Clearing caches..." + php artisan config:clear || true + php artisan view:clear || true + php artisan route:clear || true + php artisan cache:clear || true + php artisan optimize:clear || true +fi # Verify Vite manifest exists if [ -f public/build/manifest.json ]; then @@ -108,20 +121,29 @@ else ls -la public/build/ 2>/dev/null || echo "public/build directory does not exist" fi -# Optional: Run migrations if needed -# php artisan migrate --force +# Optional: Run migrations if needed (with safety for production) +if [ "$AUTO_MIGRATE" = "true" ] || [ "$APP_ENV" != "production" ]; then + echo "Running migrations..." + php artisan migrate --force +fi echo "========================================" echo "Setup complete. Starting application..." echo "========================================" -# Start the application with proper error handling -if [ "$MODE" = "staging" ]; then - echo "Starting DIRECT PHP server on port 8000 (Bypassing artisan serve)..." +# Start the application based on environment +if [ "$APP_ENV" = "production" ] || [ "$MODE" = "production" ]; then + echo "Starting PHP built-in server on port 8000 (Production mode)..." + echo "Document root: /var/www/html/public" + echo "Workers: Single-threaded PHP server (use Nginx for production scaling)" + # Use direct php -S for production (optimized) + exec php -d opcache.enable=1 -d opcache.memory_consumption=128 -d opcache.max_accelerated_files=10000 -S 0.0.0.0:8000 -t public +elif [ "$MODE" = "staging" ]; then + echo "Starting PHP built-in server on port 8000 (Staging mode)..." # 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 + exec php -d opcache.enable=0 -S 0.0.0.0:8000 -t public else - echo "Starting PHP-FPM on port 9000..." + echo "Starting PHP-FPM on port 9000 (Development mode)..." # Ensure PHP-FPM is properly configured exec php-fpm -F fi \ No newline at end of file