FROM php:7.3-apache

ENV LC_ALL=C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive
ENV ACCEPT_EULA=Y
ENV TERM=xterm

#Initialize
RUN echo "last edit 2021-12-13"
RUN apt-get update --allow-releaseinfo-change
RUN apt-get purge -y php*
RUN apt-get update --allow-releaseinfo-change && apt-get install -y --no-install-recommends apt-utils --no-install-recommends apt-transport-https --no-install-recommends software-properties-common

RUN apt-get update --allow-releaseinfo-change

RUN apt-get install -y curl git iputils-ping libxml2-dev libzip-dev unzip vim zip zlib1g-dev
RUN docker-php-ext-install bcmath ctype json mbstring mysqli pdo pdo_mysql tokenizer xml zip soap
RUN pecl install xdebug-3.1.5 \
    && docker-php-ext-enable xdebug
#install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
ENV COMPOSER_ALLOW_SUPERUSER=1
WORKDIR /var/www/html/

RUN apt-get update --allow-releaseinfo-change
RUN apt-get clean -y
RUN apt-get autoclean -y
RUN apt-get autoremove -y

COPY build/conf/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
COPY build/conf/config /config
COPY build/conf/php/php.ini /usr/local/etc/php/php.ini
COPY build/conf/php/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY build/conf/php/error_reporting.ini /usr/local/etc/php/conf.d/error_reporting.ini

RUN apt-get update --allow-releaseinfo-change && apt-get -y install cron
COPY build/conf/crontab/all-crons /etc/cron.d/all-crons
RUN chmod 0644 /etc/cron.d/all-crons
RUN crontab /etc/cron.d/all-crons
RUN mkdir -p /var/log/crontab/
RUN touch /var/log/crontab/cron.log

COPY build/.ssh/ /root/.ssh/
RUN chmod 600 /root/.ssh/authorized_keys
RUN chmod 600 /root/.ssh/id_rsa
COPY . .
ENV COMPOSER_MEMORY_LIMIT=-1
RUN composer install --no-dev --prefer-dist --no-scripts --no-progress --no-suggest

COPY build/conf/docker-php-entrypoint /usr/local/bin/docker-php-entrypoint
RUN chmod +x /usr/local/bin/docker-php-entrypoint
EXPOSE 80
CMD ["apache2-foreground"]
