FROM php:8.3-fpm

# Install supervisor, inotify-tools, dependencies for MySQL, and SSL-related packages
RUN apt-get update && apt-get install -y \
    supervisor \
    inotify-tools \
    default-mysql-client \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libssl-dev \
    openssl && \
    docker-php-ext-install pdo pdo_mysql mysqli

# Enable PHP SSL extension
RUN docker-php-ext-install opcache

# Install and configure SSL for Apache (if you use Apache with PHP-FPM)
RUN apt-get install -y apache2-utils

# Copy the supervisor config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Set the working directory
WORKDIR /var/www/html

# Create supervisor log directories
RUN mkdir -p /var/log/supervisor

# Install and configure the SSL certificates (Optional: Self-signed certificate or letsencrypt)
# If you already have certificates, copy them to your container using COPY.
# If you are using Let's Encrypt, you can configure Certbot here.

# For self-signed certificates (example):
RUN mkdir -p /etc/ssl/certs /etc/ssl/private
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=localhost"

# Configure Apache SSL (if using Apache, though you can use Nginx instead if preferred)
RUN apt-get install -y apache2
RUN a2enmod ssl
RUN a2ensite default-ssl.conf

# Start supervisor with PHP-FPM
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
