# Use an official PHP image with Apache
FROM rockstar.azurecr.io/php:latest

# Install system dependencies and PHP extensions
RUN apt-get update && apt-get install -y \
    libzip-dev \
    zip \
    unzip \
    git \
    curl \
    && docker-php-ext-install mysqli pdo pdo_mysql \
    && a2enmod rewrite

# Install Composer globally
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Set working directory
WORKDIR /var/www/html

# Copy composer files
COPY composer.json composer.lock /var/www/html/

# Copy application source code (excluding vendor if .gitignore excludes it)
COPY . /var/www/html/

# Set ownership and permissions
RUN chown -R www-data:www-data /var/www/html

# Test network connectivity
RUN apt-get update && apt-get install -y curl
RUN curl -I https://repo.packagist.org


# Install MongoDB extension with SSL support
RUN pecl install mongodb-1.17.0 \
    && docker-php-ext-enable mongodb

# Install PHP dependencies
RUN composer update --no-dev --optimize-autoloader

RUN echo "max_execution_time = 300" > /usr/local/etc/php/conf.d/uploads.ini && \
    echo "memory_limit = 512M" >> /usr/local/etc/php/conf.d/uploads.ini

# Expose port 80
EXPOSE 80

# Start Apache service
CMD ["apache2-foreground"]
