FROM php:8.2-apache

# Install PDO MySQL and cURL dependencies
RUN docker-php-ext-install pdo pdo_mysql

# Enable Apache mod_rewrite
RUN a2enmod rewrite

# Configure Apache virtual host for DocumentRoot to point to /public
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
RUN sed -ri -e 's!/var/www/html!/var/www/html/public!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!/var/www/html/public/!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Change Apache listening port to 8080 for Google Cloud Run compatibility
RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

# Copy application source code to container
COPY . /var/www/html

# Adjust file ownership for Apache web server
RUN chown -R www-data:www-data /var/www/html

# Expose port 8080
EXPOSE 8080
