FROM php:8.3-fpm

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip \
    procps \
    default-mysql-client \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mysqli mbstring exif pcntl bcmath gd sockets

# Install Redis extension
RUN pecl install redis \
    && docker-php-ext-enable redis

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Set working directory
WORKDIR /var/www/html_docker

# Copy composer files first for better caching
COPY public/composer.* ./public/

# Install dependencies (ignore platform reqs because some extensions might not be in the build env yet)
RUN cd public && composer install --no-dev --optimize-autoloader --no-scripts --ignore-platform-reqs

# Custom PHP configuration to suppress warnings in production
RUN echo "display_errors=Off" > $PHP_INI_DIR/conf.d/error-logging.ini && \
    echo "log_errors=On" >> $PHP_INI_DIR/conf.d/error-logging.ini && \
    echo "error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT" >> $PHP_INI_DIR/conf.d/error-logging.ini && echo "variables_order = \"EGPCS\"" >> $PHP_INI_DIR/conf.d/error-logging.ini

# Copy the rest of the application code
COPY . .

CMD ["php-fpm"]
