# Define a build-time variable for the PHP version, with a default of 8.1 ARG PHP_VERSION={{ php_version }} # Stage 1: Build Stage (Optional but good practice) # Use the PHP_VERSION argument in the FROM instruction FROM gitlab.forlife.one:5050/share/php:${PHP_VERSION}-fpm-alpine AS base # Set working directory inside the container WORKDIR /var/www/html # ----------------------------------------------- # 1. INSTALL SYSTEM DEPENDENCIES & PHP EXTENSIONS # ----------------------------------------------- # Added redis extension installation via PECL. RUN apk update && apk add --no-cache \ git \ curl \ libpng-dev \ libjpeg-turbo-dev \ libwebp-dev \ freetype-dev \ zip \ unzip \ libzip-dev \ oniguruma-dev \ autoconf \ g++ \ make \ nginx \ supervisor \ dcron \ postgresql-dev \ libxml2-dev \ && pecl install redis \ && docker-php-ext-enable redis \ # Configure and install other extensions && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ && docker-php-ext-install -j$(nproc) gd pdo_mysql pdo_pgsql opcache bcmath exif pcntl sockets zip mbstring dom \ # Clean up && rm -rf /var/cache/apk/* # Setup Laravel scheduler cron job to run every minute # This cron job will be run by the 'www-data' user RUN echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" > /etc/crontabs/www-data # ============================================================================ # Production stage # ============================================================================ FROM base AS production WORKDIR /var/www/html # ----------------------------------------------- # 2. APPLICATION SETUP & DEPENDENCIES # ----------------------------------------------- # Install Composer v2, suitable for modern PHP versions #COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer # Copy the Laravel application files COPY . . # Install Composer dependencies (Assuming composer.lock is present) RUN composer install --no-dev --optimize-autoloader --no-interaction # Optimize Laravel RUN php artisan optimize && \ php artisan route:clear && \ php artisan route:cache && \ php artisan config:clear && \ php artisan config:cache && \ php artisan view:clear && \ php artisan view:cache #RUN php artisan storage:link # remove this line if you do not want to run migrations on each build #RUN php artisan migrate --force # Set appropriate permissions for Laravel (www-data is the default FPM user on Alpine) RUN chown -R www-data:www-data /var/www/html \ && chmod -R 775 storage bootstrap/cache RUN ([ -d "public/cms/backend/uploads" ] && chmod -R 775 public/cms/backend/uploads) || true # ----------------------------------------------- # 3. CONFIGURATION & ENTRYPOINT (THE FIX) # ----------------------------------------------- RUN mkdir -p /run/nginx \ && chown -R www-data:www-data /run/nginx \ && chown -R www-data:www-data /var/lib/nginx # Copy Nginx Configuration (Assuming it's in the 'docker' subdirectory) # Nginx listens on port 80 and proxies PHP requests to FPM (port 9000). COPY docker/nginx.conf /etc/nginx/nginx.conf COPY docker/laravel.conf /etc/nginx/http.d/site.conf COPY docker/php.ini /usr/local/etc/php/php.ini # Copy Supervisor Configuration (Assuming it's in the 'docker' subdirectory) # Supervisor manages both Nginx and PHP-FPM processes. COPY docker/supervisord.conf /etc/supervisord.conf EXPOSE 3000 # Start Supervisor, which runs Nginx, PHP-FPM, and Cron CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]