docker/Dockerfile-php

93 lines
3.5 KiB
Text

FROM debian:bookworm-slim
ARG PHP_VERSION=7.4
ARG WKHTML=""
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y --no-install-recommends ca-certificates curl apt-transport-https lsb-release readline-common git zlib1g-dev
# PHP files based on PHP_VERSION
RUN curl -L https://packages.sury.org/php/apt.gpg -o /etc/apt/trusted.gpg.d/php.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
RUN apt-get update -y
# persistent / runtime deps
RUN apt-get install -y --no-install-recommends imagemagick apache2 msmtp msmtp-mta \
php${PHP_VERSION} php${PHP_VERSION}-bcmath php${PHP_VERSION}-cli php${PHP_VERSION}-common \
php${PHP_VERSION}-curl php${PHP_VERSION}-fpm php${PHP_VERSION}-gd php${PHP_VERSION}-gmp \
php${PHP_VERSION}-imagick php${PHP_VERSION}-intl php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-mysql php${PHP_VERSION}-opcache php${PHP_VERSION}-readline php${PHP_VERSION}-sqlite3 \
php${PHP_VERSION}-xml php${PHP_VERSION}-yaml php${PHP_VERSION}-zip php${PHP_VERSION}-apcu \
libapache2-mod-php${PHP_VERSION}
# specific PHP modules for some versions
RUN if [[ "${PHP_VERSION}" == "7.4" ]] ; then apt-get -y install php${PHP_VERSION}-json; fi
# install wkhtml if needed
RUN if [[ "${WKHTML}" != "" ]] ; then \
apt-get install -y --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev fontconfig libfreetype6 libjpeg62-turbo \
libpng16-16 libx11-6 libxcb1 libxext6 libxrender1 xfonts-75dpi xfonts-base; \
curl -L https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_arm64.deb -o /tmp/wkhtmltox.deb; \
dpkg -i /tmp/wkhtmltox.deb; \
fi
# upgrade system a second time
RUN apt-get upgrade -y
# clean all
RUN rm -rf /var/lib/apt/lists/* /var/lib/log/* /tmp/* /var/tmp/*
RUN mkdir -p /var/www/html; chown www-data:www-data /var/www/html; chmod 1777 /var/www/html
ENV APACHE_CONFDIR=/etc/apache2
ENV APACHE_ENVVARS=$APACHE_CONFDIR/envvars
RUN sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS"; \
\
# setup directories and permissions
. "$APACHE_ENVVARS"; \
for dir in \
"$APACHE_LOCK_DIR" \
"$APACHE_RUN_DIR" \
"$APACHE_LOG_DIR" \
; do \
rm -rvf "$dir"; \
mkdir -p "$dir"; \
chown "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$dir"; \
# allow running as an arbitrary user (https://github.com/docker-library/php/issues/743)
chmod 1777 "$dir"; \
done; \
\
# delete the "index.html" that installing Apache drops in here
rm -rvf /var/www/html/*; \
\
# logs should go to stdout / stderr
ln -sfT /dev/stderr "$APACHE_LOG_DIR/error.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/access.log"; \
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"
# symbolic link for easy use of php.ini
RUN ln -s /etc/php/${PHP_VERSION}/apache2/conf.d /etc/php/conf.d
# apache site and modules
COPY apache/site.conf /etc/apache2/sites-available/site.conf
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN a2dismod mpm_event
RUN a2dissite 000-default
RUN a2enmod mpm_prefork # Apache + PHP requires pre-forking Apache for best results
RUN a2enmod rewrite
RUN a2enmod remoteip
RUN a2enmod setenvif
RUN a2ensite site
# apache init
COPY apache/apache2-foreground /usr/local/bin/apache2-foreground
RUN chmod +x /usr/local/bin/apache2-foreground
WORKDIR /var/www/html
EXPOSE 80
CMD ["apache2-foreground"]