FROM php:8.2-apache

RUN apt-get update && apt-get install -y \
    libpng-dev libonig-dev libxml2-dev libzip-dev unzip git curl libicu-dev \
    && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip intl

RUN a2enmod rewrite

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

# Set working directory inside container
WORKDIR /var/www/html

# Copy composer.json and composer.lock first (to leverage Docker cache)
COPY composer.json composer.lock ./

# Install dependencies via composer
RUN composer install --no-dev --optimize-autoloader

# Copy the rest of your app code
COPY . .

# Fix permissions
RUN chown -R www-data:www-data storage bootstrap/cache

EXPOSE 80
