diff --git a/Dockerfile b/Dockerfile index 8235acb..1ff11fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,41 @@ -FROM php:7.4-fpm +FROM alpine -# Ubuntu repo updates -RUN apt-get update +# Initial updates +RUN apk update && \ + apk upgrade && \ + rm -rf /var/cache/apk/* /var/log/* -# Install dependencies -RUN apt-get update && apt-get install -y --no-install-recommends \ - apt-utils \ - apache2 \ - unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libyaml-dev \ - libzip4 \ - libzip-dev \ - zlib1g-dev \ - libicu-dev \ - libmemcached11 \ - libmemcachedutil2 \ - build-essential \ - libmemcached-dev \ - g++ \ - git \ - cron \ - vim \ - && docker-php-ext-install opcache \ - && docker-php-ext-configure intl \ - && docker-php-ext-install intl \ - && docker-php-ext-configure gd --with-freetype --with-jpeg \ - && docker-php-ext-install -j$(nproc) gd \ - && docker-php-ext-install zip \ - && rm -rf /var/lib/apt/lists/* +# Install packages +RUN apk add apache2 apache2-proxy composer zip curl -# Enable Apache Rewrite + Expires Module -RUN a2enmod rewrite expires && \ - sed -i 's/ServerTokens OS/ServerTokens ProductOnly/g' \ - /etc/apache2/conf-available/security.conf +# Configure to use php fpm and don't use /var/www to store everything (modules and logs) +RUN sed -i 's/LoadModule mpm_prefork_module/#LoadModule mpm_prefork_module/g' /etc/apache2/httpd.conf && \ + sed -i 's/#LoadModule mpm_event_module/LoadModule mpm_event_module/g' /etc/apache2/httpd.conf && \ + sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/g' /etc/apache2/httpd.conf && \ + # remove useless module bundled with proxy + sed -i 's/LoadModule lbmethod/#LoadModule lbmethod/g' /etc/apache2/conf.d/proxy.conf && \ + # change ServerRoot + sed -i 's/var\/www\/localhost\/htdocs/var\/www/g' /etc/apache2/httpd.conf && \ + sed -i 's/ServerRoot \/var\/www/ServerRoot \/usr\/local\/apache/g' /etc/apache2/httpd.conf && \ + # change user and group + sed -i 's/^User apache/User www-data/g' /etc/apache2/httpd.conf && \ + sed -i 's/^Group apache/Group www-data/g' /etc/apache2/httpd.conf && \ + # Prepare env and create user + mkdir -p /var/log/apache2 && \ + groupdel www-data && \ + groupmod -g 101 -n www-data apache && \ + usermod -g 101 -u 100 -l www-data -d /var/www apache && \ + chown www-data:www-data /var/log/apache2 /var/www && \ + # Clean base directory and create required ones + rm -rf /var/www/* && \ + mkdir -p /run/apache2 /usr/local/apache && \ + ln -s /usr/lib/apache2 /usr/local/apache/modules && \ + ln -s /var/log/apache2 /usr/local/apache/logs -# Install composer -RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +COPY vhost.conf /etc/apache2/conf.d/vhost.conf -RUN pecl install apcu \ - && pecl install yaml-2.1.0 \ - && docker-php-ext-enable apcu yaml gd opcache intl zip - -# Set user to www-data -RUN chown www-data:www-data /var/www -USER www-data +ENV APACHE_UID 100 +ENV APACHE_GID 101 # Define Grav specific version of Grav or use latest stable ENV GRAV_VERSION latest @@ -68,6 +57,9 @@ EXPOSE 80/tcp USER root # provide container inside image for data persistence -VOLUME ["/var/www/html"] +VOLUME ["/var/www"] -CMD ["sh", "-c", "apache2-foreground"] \ No newline at end of file +COPY run.sh /run.sh +RUN chmod u+x /run.sh + +CMD ["/run.sh"] \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..d5d477e --- /dev/null +++ b/run.sh @@ -0,0 +1,10 @@ +#!/bin/sh +CURRENT_APACHE_ID=$(id -u www-data) +if [ "$CURRENT_APACHE_ID" != "$APACHE_UID" ]; then + echo "Fixing permissions for www-data" + usermod -u $APACHE_UID www-data + groupmod -g $APACHE_GID www-data + chown -R www-data:www-data /run/apache2 /var/www +fi + +exec /usr/sbin/httpd -DFOREGROUND; diff --git a/vhost.conf b/vhost.conf new file mode 100644 index 0000000..0078233 --- /dev/null +++ b/vhost.conf @@ -0,0 +1,45 @@ +ServerName localhost + + + ServerName localhost + + ## Vhost docroot + DocumentRoot /var/www + + ## Take .htaccess.local in priority + AccessFileName .htaccess.local .htaccess + + ## PHP-FPM connection + ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/$1 + DirectoryIndex index.php + + ## Directories, + + Require all denied + + + + Require all denied + + + + Require all denied + + + + Options -Indexes +FollowSymLinks +IncludesNOEXEC -MultiViews + AllowOverride All + Require all granted + + + SetHandler "proxy:fcgi://php:9000" + + + + + ProxySet timeout=1200 + + + ## Logging : hide version + ServerSignature Off +