FROM php:7.3-apache-stretch

# Set working directory
WORKDIR /var/www/html
#COPY .env.example .env

# Install PDO MySQL driver
RUN docker-php-ext-install pdo_mysql

# Install git, zip and composer + enable Apache modules: rewrite, headers
RUN apt update \
 && apt install -y git zip \
 && curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
 && a2enmod rewrite headers

# RUN mkdir bootstrap/cache
# RUN mkdir storage

# Copy files to WORKDIR and install dependencies
COPY . .

RUN usermod -u 1000 www-data; \
    chown -R www-data:www-data /var/www/html

RUN find /var/www/html -type f -exec chmod 664 {} \;

RUN find /var/www/html -type d -exec chmod 775 {} \;

RUN cd /var/www/html \
&& chgrp -R www-data storage bootstrap/cache \
&& chmod -R ug+rwx storage bootstrap/cache

RUN composer install
RUN php artisan key:generate
RUN php artisan jwt:secret

RUN rm /etc/apache2/sites-available/000-default.conf

RUN rm /etc/apache2/sites-available/default-ssl.conf

COPY apache/000-default.conf /etc/apache2/sites-available/

COPY apache/000-default.conf /etc/apache2/sites-enabled/

# Set www-data as owner for files
RUN usermod -u 1000 www-data; \
    chown -R www-data:www-data /var/www/html

RUN chmod -R ug+rwx /var/www/html

# Apache is listening on port 80
EXPOSE 80
EXPOSE 443

# Change Apache root directory
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

