FROM ubuntu:latest

RUN apt-get update && apt-get install -y \
    apache2 \
    php \
    php-mysql \
    php-ldap \
    libapache2-mod-php \
    libapache2-mod-xsendfile \
	ca-certificates \
	git \
	openssl \
	sssd \
	ldap-utils \
	ffmpeg \
	curl \
    && apt-get clean

RUN update-ca-certificates

# enable userdir and ldap modules
RUN a2enmod userdir
RUN a2enmod authnz_ldap

# Enable file uploads and configure PHP settings
RUN sed -i "s/^\(file_uploads\s*=\s*\)Off/\1On/" /etc/php/8.3/apache2/php.ini \
    && sed -i "s/^\(upload_max_filesize\s*=\s*\)[0-9]\+/upload_max_filesize = 500M/" /etc/php/8.3/apache2/php.ini \
    && sed -i "s/^\(post_max_size\s*=\s*\)[0-9]\+/post_max_size = 500M/" /etc/php/8.3/apache2/php.ini

COPY userdir.conf /etc/apache2/mods-available/userdir.conf

# change apache log level
RUN sed -i '/^LogLevel /s/ .*/ debug/' /etc/apache2/apache2.conf

# disable sss in nsswitch.conf
RUN sed -i 's/sss//g' /etc/nsswitch.conf

# enable sss in nsswitch.conf for passwd, group and shadow
RUN sed -i '/^\(\passwd\|group\|hosts\|shadow\)/s/$/ sss/' /etc/nsswitch.conf

# Expose the HTTP port
EXPOSE 80

# Start Apache in the foreground
CMD ["apachectl", "-D", "FOREGROUND"]
