diff --git a/Dockerfile b/Dockerfile index e78f90a..7443207 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,9 @@ +# Use official PHP 8.2 FPM image FROM php:8.2-fpm +# Set working directory +WORKDIR /var/www/html + # Install dependencies RUN apt-get update && apt-get install -y \ libpng-dev \ @@ -9,14 +13,26 @@ RUN apt-get update && apt-get install -y \ zip \ unzip \ curl \ + git \ + libonig-dev \ + libxml2-dev \ + procps \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install gd pdo pdo_mysql -# Set working directory -WORKDIR /var/www/html +# Copy the rest of Laravel files +COPY laravel/ . -# Copy application -COPY . . +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +# Copy only essential files for better build caching +COPY laravel/composer.json laravel/composer.lock ./ +RUN composer install --no-dev --optimize-autoloader + +# Set permissions +RUN chown -R www-data:www-data /var/www/html +RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache # Copy entrypoint script and make it executable COPY entrypoint.sh /entrypoint.sh @@ -30,7 +46,6 @@ CMD ["php-fpm"] - # FROM php:8.2-fpm # RUN apt-get update && apt-get install -y \ diff --git a/docker-compose.yml b/docker-compose.yml index 375c6ef..c5a4b9c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -29,7 +29,7 @@ services: - DB_USERNAME=root - DB_PASSWORD=rootpassword healthcheck: - test: ["CMD", "curl", "-f", "http://localhost"] + test: ["CMD", "pgrep", "php-fpm"] # Corrected to check PHP-FPM instead of relying on Nginx interval: 10s timeout: 5s retries: 5 @@ -50,6 +50,7 @@ services: volumes: mysql-data: + # services: # mysql: # image: mysql:latest diff --git a/entrypoint.sh b/entrypoint.sh index 873ed12..3308987 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,6 +8,12 @@ until nc -z -v -w30 mysql 3306; do done echo "✅ MySQL is up and running!" +# Fix ownership and permissions for storage and cache directories +echo "🔧 Setting permissions for storage and cache..." +chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache +chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache +echo "✅ Permissions set successfully!" + # Run Laravel migrations php artisan migrate --force @@ -15,7 +21,6 @@ php artisan migrate --force exec "$@" - # #!/bin/bash # # Fix ownership and permissions for storage directories # chown -R www-data:www-data /var/www/html/storage diff --git a/laravel_initial b/laravel_initial index a6b9153..939ee01 160000 --- a/laravel_initial +++ b/laravel_initial @@ -1 +1 @@ -Subproject commit a6b9153dc1438eeb542f2bbe3f8687e9c078c0fa +Subproject commit 939ee016159d4f344b644a61819b6f96e66e49cb diff --git a/nginx.conf b/nginx.conf index 38ac455..22431d1 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,3 +1,4 @@ + server { listen 80; index index.php index.html; @@ -21,7 +22,6 @@ server { add_header X-XSS-Protection "1; mode=block"; } - # server { # listen 80; # index index.php index.html; diff --git a/wait-for-it.sh b/wait-for-it.sh index b269e1b..f62f4fb 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -11,4 +11,4 @@ until nc -z "$HOST" "$PORT"; do done echo "$host:$port is now available, running command..." -exec $cmd +exec $cmd \ No newline at end of file