FROM ubuntu:20.04
ENV TYPE="SERVER"

RUN apt-get -y update
# OS update, then clean up
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install tzdata

RUN apt-get -yq upgrade && \
    apt-get -yq --no-install-recommends install \
        software-properties-common \
        apt-transport-https \
        ca-certificates \
        aptitude \
        wget \
        unzip mysql-client && \
    apt-get install -y \
    curl \
    locales \
    nano \
    apache2 \
    php \
    libapache2-mod-php \
    php-redis \
    php-bcmath \
    php-gd \
    php-json \
    php-sqlite3 \
    php-mysql \
    php-curl \
    php-xml \
    php-mbstring \
    php-zip \
    php-dev php-pear php-gmp \
    mcrypt \
    vim && \
    apt install -y composer pwgen netcat supervisor && \
    apt-get clean && \
    rm -rf /tmp/* /var/tmp/* /var/lib/apt/archive/* /var/lib/apt/lists/*

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.22

# Set locales
RUN locale-gen en_US.UTF-8 en_GB.UTF-8 de_DE.UTF-8 es_ES.UTF-8 fr_FR.UTF-8 it_IT.UTF-8 km_KH sv_SE.UTF-8 fi_FI.UTF-8


# Configure PHP
COPY php/php.ini /etc/php/7.4/apache2/conf.d/app.ini

# Configure apache
RUN a2enmod rewrite expires
RUN echo "ServerName localhost" | tee /etc/apache2/conf-available/servername.conf
RUN a2enconf servername
RUN a2enmod env

# vhost
COPY php/www.conf /etc/apache2/sites-available/
RUN a2dissite 000-default
RUN a2ensite www.conf


RUN mkdir -p /var/log/supervisor
# Set working directory
WORKDIR /var/www

# Copy www directory
COPY ./ /var/www/

RUN composer install && \
    composer update
RUN chmod +x /var/www/entrypoint.sh

COPY php/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

VOLUME /var/www/
EXPOSE 80
CMD [ "php", "-S", "[::]:80", "-t", "/var/www/" ]

ENTRYPOINT ["/var/www/entrypoint.sh"]
