ARG DEBIAN_VERSION=stretch

FROM debian:${DEBIAN_VERSION}

# FROM https://github.com/ZHAJOR/Docker-Apache-2.4-Php-5.6-for-Laravel
MAINTAINER Robin Thoni <robin@rthoni.com>

RUN apt-get update && apt-get -y install\
        wget &&\
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG ZABBIX_VERSION=4.0

RUN if [ "$(uname -m)" = "x86_64" ]; then echo -n "debian"; else echo -n "raspbian"; fi > /tmp/distrib &&\
    wget http://repo.zabbix.com/zabbix/${ZABBIX_VERSION}/$(cat /tmp/distrib)/pool/main/z/zabbix-release/zabbix-release_${ZABBIX_VERSION}-2+stretch_all.deb -O /tmp/zabbix.deb &&\
    rm /tmp/distrib &&\
    dpkg -i /tmp/zabbix.deb

RUN apt-get update && apt-get -y install\
        zabbix-frontend-php\
        apache2=2.4.*\
        libapache2-mod-php\
        php\
        php-mcrypt\
        php-pgsql\
        php-mysql\
        php-gd\
        php-curl\
        php-imap &&\
        apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN /usr/sbin/a2enmod rewrite &&\
    rm -rf /var/www/html &&\
    mkdir -p /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html &&\
    chown -R www-data:www-data /var/lock/apache2 /var/run/apache2 /var/log/apache2 /var/www/html

RUN rm -rf /var/log/* &&\
    mkdir -p /var/log/apache2 &&\
    ln -s /dev/stderr /var/log/apache2/error.log &&\
    ln -s /dev/stdout /var/log/apache2/access.log &&\
    ln -s /dev/stdout /var/log/apache2/other_vhosts_access.log

COPY apache2.conf /etc/apache2/apache2.conf

COPY zabbix.conf.php /etc/zabbix/web/zabbix.conf.php

COPY php.ini /etc/php/7.0/apache2/php.ini

COPY ./vars-vars /etc/vars-vars

COPY ./vars-files /etc/vars-files

COPY ./run.sh /run.sh

EXPOSE 80

CMD ["/run.sh"]
