From 3e1c883cb5218fad7cc1d1d780221491e30d7e5c Mon Sep 17 00:00:00 2001 From: "m.marjorie" Date: Mon, 24 Mar 2025 09:20:29 +0000 Subject: [PATCH] Update start.sh to handle missing or empty APP_KEY --- start.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/start.sh b/start.sh index 0d97698..b4d3174 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,19 @@ #!/bin/sh sleep 10 -if [ -z "$(grep '^APP_KEY=' /var/www/html/.env)" ]; then - php artisan key:generate + +# Check if .env file exists, if not create it from .env.example +if [ ! -f /var/www/html/.env ]; then + cp /var/www/html/.env.example /var/www/html/.env fi -php artisan migrate --force -php-fpm + +# Check if APP_KEY is missing or empty +if [ -z "$(grep '^APP_KEY=.\+' /var/www/html/.env)" ]; then + echo "Generating APP_KEY..." + php artisan key:generate || { echo "Failed to generate APP_KEY"; exit 1; } +fi + +# Run migrations +php artisan migrate --force || { echo "Failed to run migrations"; exit 1; } + +# Start PHP-FPM +php-fpm || { echo "Failed to start PHP-FPM"; exit 1; }