FROM php:8.5.6-apache

RUN apt-get update && apt-get install -y \
    unzip \
    zip \
    git \
    libzip-dev \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
 && docker-php-ext-configure gd --with-freetype --with-jpeg \
 && docker-php-ext-install \
    mysqli \
    pdo \
    pdo_mysql \
    gd \
    zip \
 && a2enmod rewrite \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html

# 1. copy only composer files first (for caching)
COPY composer.json composer.lock ./

RUN composer install --no-dev --optimize-autoloader

# 2. copy full project
COPY . .

COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf

# Session files live under application/cache/sessions (see config.php sess_save_path).
# cache/* is gitignored except sessions/.gitkeep, so ensure the dir exists and is writable.
RUN mkdir -p /var/www/html/application/cache/sessions \
 && chown -R www-data:www-data /var/www/html \
 && chmod 700 /var/www/html/application/cache/sessions