# Use the official PHP 8.2 image with Apache disabled
FROM php:8.2.15-fpm
# Set the working directory inside the container
WORKDIR /var/www/html

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


# Install required extensions and dependencies
# Install required extensions and dependencies
# Install required extensions and dependencies
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        $PHPIZE_DEPS \
        libpng-dev \
        libjpeg62-turbo-dev \
        libfreetype6-dev \
        libxml2-dev \
        libonig-dev \
        libmagickwand-dev \
        libmagickcore-dev \
        imagemagick \
        pkg-config \
        zip \
        unzip \
        git \
        curl \
        redis-tools \
        libzip-dev \
        libssl-dev \
        ca-certificates \
        mariadb-client; \
    update-ca-certificates; \
    docker-php-ext-configure gd --with-freetype --with-jpeg; \
    docker-php-ext-install -j"$(nproc)" \
        mbstring \
        exif \
        pcntl \
        bcmath \
        gd \
        pdo_mysql \
        mysqli \
        zip; \
    pecl install imagick-3.7.0; \
    docker-php-ext-enable imagick; \
    apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $PHPIZE_DEPS; \
    rm -rf /var/lib/apt/lists/*

## Do not copy application code at build time; it will be bind-mounted by docker-compose
## If you wish to build a self-contained image, uncomment the next line and adjust the path:
## COPY services/nginx/app /var/www/html

# Set the appropriate permissions for the working directory
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html

## Composer installs are performed at container start by docker-entrypoint.sh
ENV COMPOSER_ALLOW_SUPERUSER=1

## Ensure workdir is correct
WORKDIR /var/www/html

# Copy and enable entrypoint that installs Composer deps on first run
#COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
#RUN chmod +x /usr/local/bin/docker-entrypoint.sh

# Expose port 9000
EXPOSE 9000

#ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["php-fpm"]