FROM ubuntu:bionic

RUN apt-get update && \
    apt-get -y upgrade && \
    DEBIAN_FRONTEND=noninteractive apt-get -y install \
        apache2 php7.2 libapache2-mod-php7.2 libcap2-bin curl

RUN a2enmod php7.2

#RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
#RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini

ENV APACHE_RUN_USER 1000220000
ENV APACHE_RUN_GROUP 5100
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

RUN mkdir -p /var/log/apache2 && chown -R ${APACHE_RUN_USER} /var/log/apache2 && \
    mkdir -p /var/lock/apache2 && chown -R ${APACHE_RUN_USER} /var/lock/apache2 && \
    mkdir -p /var/run/apache2 && chown -R ${APACHE_RUN_USER} /var/run/apache2 && \
    setcap 'cap_net_bind_service=+ep' /usr/sbin/apache2

ADD config/apache-config.conf /etc/apache2/sites-enabled/000-default.conf
ADD config/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

RUN rm -rf /var/www/html/*
ADD . /var/www/html
RUN chown -R ${APACHE_RUN_USER} /var/www/html

VOLUME /var/www/html/patchpanel/data

USER ${APACHE_RUN_USER}

EXPOSE 80

WORKDIR /var/www/html
ENTRYPOINT /docker-entrypoint.sh
