FROM php:8.3-apache

# Apache rewrite so .htaccess routing works
RUN a2enmod rewrite

# SQLite + PDO
RUN apt-get update && apt-get install -y libsqlite3-dev \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install pdo_sqlite

# Let per-directory .htaccess override (needed for our RewriteRule)
RUN sed -ri 's!AllowOverride None!AllowOverride All!g' /etc/apache2/apache2.conf

# App files. data/ is also mounted as a volume in docker-compose so the
# DB + master key persist across rebuilds — but we COPY it too so a
# bare `docker run` still boots.
COPY . /var/www/html/

# Entrypoint makes sure data/ is writable by www-data inside the
# container (mounts from the host can otherwise land as root:root).
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod +x /usr/local/bin/docker-entrypoint.sh

EXPOSE 80
CMD ["docker-entrypoint.sh"]
