mirror of
https://github.com/jkaninda/laravel-php-fpm.git
synced 2026-11-13 08:37:15 +00:00
Merge pull request #90 from jkaninda/dev
Upgrade images to PHP 8.5 and fix php-fpm not starting as root
This commit is contained in:
1 parent
033c6b213f
commit
7799d2fbc2
23 files changed
+705
-526
No files matched your search
@@ -2,6 +2,19 @@ FROM php:7.2-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV APP_DIR=/var/www/html \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0
|
||||
ENV NODE_VERSION=16.x
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
@@ -88,7 +101,7 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
RUN usermod -u ${USER_ID} ${USER_NAME}
|
||||
RUN groupmod -g ${USER_ID} ${GROUP_NAME}
|
||||
RUN groupmod -g ${GROUP_ID} ${GROUP_NAME}
|
||||
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
|
||||
|
||||
@@ -2,6 +2,19 @@ FROM php:7.3-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV APP_DIR=/var/www/html \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0
|
||||
ENV NODE_VERSION=16.x
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
@@ -88,7 +101,7 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
RUN usermod -u ${USER_ID} ${USER_NAME}
|
||||
RUN groupmod -g ${USER_ID} ${GROUP_NAME}
|
||||
RUN groupmod -g ${GROUP_ID} ${GROUP_NAME}
|
||||
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
|
||||
|
||||
@@ -2,6 +2,19 @@ FROM php:7.4-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV APP_DIR=/var/www/html \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0
|
||||
ENV NODE_VERSION=16.x
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
@@ -89,7 +102,7 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
RUN usermod -u ${USER_ID} ${USER_NAME}
|
||||
RUN groupmod -g ${USER_ID} ${GROUP_NAME}
|
||||
RUN groupmod -g ${GROUP_ID} ${GROUP_NAME}
|
||||
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
|
||||
|
||||
@@ -2,6 +2,19 @@ FROM php:8.0-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV APP_DIR=/var/www/html \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0
|
||||
ENV NODE_VERSION=16.x
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
@@ -89,7 +102,7 @@ RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
|
||||
RUN usermod -u ${USER_ID} ${USER_NAME}
|
||||
RUN groupmod -g ${USER_ID} ${GROUP_NAME}
|
||||
RUN groupmod -g ${GROUP_ID} ${GROUP_NAME}
|
||||
RUN chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
|
||||
|
||||
+85
-86
@@ -1,104 +1,103 @@
|
||||
ARG phpVersion=8.3-dev
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG phpVersion=8.5
|
||||
FROM composer:2 AS composer
|
||||
|
||||
FROM php:${phpVersion}-fpm
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ENV NODE_MAJOR=20
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
ENV USER_NAME=www-data
|
||||
ARG GROUP_NAME=www-data
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
git \
|
||||
curl \
|
||||
libfreetype6-dev \
|
||||
libjpeg62-turbo-dev \
|
||||
libmemcached-dev \
|
||||
libzip-dev \
|
||||
libpng-dev \
|
||||
libonig-dev \
|
||||
libxml2-dev \
|
||||
librdkafka-dev \
|
||||
libpq-dev \
|
||||
openssh-server \
|
||||
zip \
|
||||
unzip \
|
||||
supervisor \
|
||||
sqlite3 \
|
||||
nano \
|
||||
cron
|
||||
# Install Nodejs
|
||||
RUN apt-get update && apt-get install -y ca-certificates curl gnupg
|
||||
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
|
||||
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
|
||||
RUN apt-get update && apt-get install nodejs -y
|
||||
ARG NODE_MAJOR=24
|
||||
|
||||
# Clear cache
|
||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||
# Install Kafka
|
||||
RUN git clone https://github.com/arnaud-lb/php-rdkafka.git\
|
||||
&& cd php-rdkafka \
|
||||
&& phpize \
|
||||
&& ./configure \
|
||||
&& make all -j 5 \
|
||||
&& make install
|
||||
LABEL org.opencontainers.image.title="laravel-php-fpm" \
|
||||
org.opencontainers.image.description="PHP-FPM image for Laravel and PHP applications" \
|
||||
org.opencontainers.image.source="https://github.com/jkaninda/laravel-php-fpm" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.authors="Jonas Kaninda"
|
||||
|
||||
# Install Rdkafka and enable it
|
||||
RUN docker-php-ext-enable rdkafka \
|
||||
&& cd .. \
|
||||
&& rm -rf /php-rdkafka
|
||||
ENV DOCUMENT_ROOT=${WORKDIR} \
|
||||
APP_DIR=${WORKDIR} \
|
||||
USER_NAME=www-data \
|
||||
NODE_MAJOR=${NODE_MAJOR} \
|
||||
LARAVEL_PROCS_NUMBER=1 \
|
||||
LARAVEL_QUEUE_WORKER_ENABLED=true \
|
||||
LARAVEL_QUEUE_OPTIONS="--sleep=3 --tries=3" \
|
||||
LARAVEL_SCHEDULER_ENABLED=true \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0 \
|
||||
PHP_FPM_PM=dynamic \
|
||||
PHP_FPM_PM_MAX_CHILDREN=20 \
|
||||
PHP_FPM_PM_START_SERVERS=2 \
|
||||
PHP_FPM_PM_MIN_SPARE_SERVERS=1 \
|
||||
PHP_FPM_PM_MAX_SPARE_SERVERS=3 \
|
||||
PHP_FPM_PM_MAX_REQUESTS=500
|
||||
|
||||
# Install PHP extensions zip, mbstring, exif, bcmath, intl
|
||||
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
|
||||
RUN docker-php-ext-install zip mbstring exif pcntl bcmath -j$(nproc) gd intl
|
||||
# Runtime tools and Node.js
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates curl gnupg git openssh-client unzip zip \
|
||||
supervisor cron sqlite3 nano; \
|
||||
mkdir -p /etc/apt/keyrings; \
|
||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg; \
|
||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends nodejs; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Redis and enable it
|
||||
RUN pecl install redis && docker-php-ext-enable redis
|
||||
# PHP extensions (build dependencies are purged, runtime libraries are kept)
|
||||
RUN set -eux; \
|
||||
savedAptMark="$(apt-mark showmanual)"; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
libfreetype6-dev libjpeg62-turbo-dev libpng-dev libwebp-dev \
|
||||
libicu-dev libmemcached-dev libonig-dev libpq-dev librdkafka-dev \
|
||||
libxml2-dev libzip-dev zlib1g-dev; \
|
||||
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \
|
||||
docker-php-ext-install -j"$(nproc)" bcmath exif gd intl mbstring pcntl pdo_mysql pdo_pgsql zip; \
|
||||
pecl install redis memcached rdkafka; \
|
||||
docker-php-ext-enable redis memcached rdkafka; \
|
||||
# OPcache is always compiled in since PHP 8.5
|
||||
if ! php -m | grep -qi '^zend opcache$'; then docker-php-ext-install opcache; fi; \
|
||||
apt-mark auto '.*' > /dev/null; \
|
||||
apt-mark manual $savedAptMark > /dev/null; \
|
||||
find /usr/local -type f \( -executable -o -name '*.so' \) -exec ldd '{}' ';' 2>/dev/null \
|
||||
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); printf "*%s\n", so }' \
|
||||
| sort -u | xargs -r dpkg-query --search | awk -F: '!/^diversion/ { print $1 }' | sort -u | xargs -r apt-mark manual; \
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/pear ~/.pearrc; \
|
||||
! php -m 2>&1 | grep -iE 'warning|unable to load'
|
||||
|
||||
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
|
||||
|
||||
|
||||
# Install the php memcached extension
|
||||
RUN pecl install memcached && docker-php-ext-enable memcached
|
||||
|
||||
# Install the PHP pdo_mysql extention
|
||||
RUN docker-php-ext-install pdo_mysql
|
||||
|
||||
# Install the PHP pdo_pgsql extention
|
||||
RUN docker-php-ext-install pdo_pgsql
|
||||
|
||||
# Install PHP Opcache extention
|
||||
RUN docker-php-ext-install opcache
|
||||
|
||||
|
||||
# Install Composer
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
|
||||
# Set working directory
|
||||
WORKDIR $WORKDIR
|
||||
|
||||
RUN rm -Rf /var/www/* && \
|
||||
mkdir -p /var/www/html
|
||||
RUN rm -Rf /var/www/* && mkdir -p ${WORKDIR} /etc/supervisor/conf.d /var/log/supervisor
|
||||
|
||||
ADD src/index.php $WORKDIR/index.php
|
||||
ADD src/php.ini $PHP_INI_DIR/conf.d/
|
||||
ADD src/opcache.ini $PHP_INI_DIR/conf.d/
|
||||
ADD src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
|
||||
COPY src/entrypoint.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
RUN ln -s /usr/local/bin/entrypoint.sh /
|
||||
|
||||
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
COPY src/index.php $WORKDIR/index.php
|
||||
COPY src/php.ini src/opcache.ini $PHP_INI_DIR/conf.d/
|
||||
COPY src/php-fpm.d/zz-laravel.conf /usr/local/etc/php-fpm.d/zz-laravel.conf
|
||||
COPY src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
COPY --chmod=755 src/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN ln -s /usr/local/bin/entrypoint.sh /entrypoint.sh
|
||||
|
||||
RUN usermod -u ${USER_ID} ${USER_NAME} && \
|
||||
groupmod -g ${USER_ID} ${GROUP_NAME} && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/www && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/log/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /etc/supervisor/conf.d/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} $PHP_INI_DIR/conf.d/ && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /tmp
|
||||
groupmod -g ${GROUP_ID} ${GROUP_NAME} && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/www /var/log /etc/supervisor/conf.d $PHP_INI_DIR/conf.d /tmp
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --start-interval=2s --retries=3 \
|
||||
CMD php -r 'exit(@fsockopen("127.0.0.1", 9000) ? 0 : 1);'
|
||||
|
||||
EXPOSE 9000
|
||||
CMD [ "entrypoint" ]
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
CMD ["entrypoint"]
|
||||
@@ -1,24 +1,93 @@
|
||||
ARG phpVersion=8.3-dev
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG phpVersion=8.5
|
||||
FROM composer:2 AS composer
|
||||
|
||||
FROM php:${phpVersion}-fpm-alpine
|
||||
ARG WORKDIR=/var/www/html
|
||||
ENV DOCUMENT_ROOT=${WORKDIR}
|
||||
ENV LARAVEL_PROCS_NUMBER=1
|
||||
ARG GROUP_ID=1000
|
||||
ARG USER_ID=1000
|
||||
ENV USER_NAME=www-data
|
||||
ARG GROUP_NAME=www-data
|
||||
|
||||
# Install the PHP pdo_mysql extention
|
||||
RUN docker-php-ext-install pdo_mysql
|
||||
LABEL org.opencontainers.image.title="laravel-php-fpm" \
|
||||
org.opencontainers.image.description="PHP-FPM image for Laravel and PHP applications (Alpine)" \
|
||||
org.opencontainers.image.source="https://github.com/jkaninda/laravel-php-fpm" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.authors="Jonas Kaninda"
|
||||
|
||||
# Install Composer
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
ENV DOCUMENT_ROOT=${WORKDIR} \
|
||||
APP_DIR=${WORKDIR} \
|
||||
USER_NAME=www-data \
|
||||
LARAVEL_PROCS_NUMBER=1 \
|
||||
LARAVEL_QUEUE_WORKER_ENABLED=true \
|
||||
LARAVEL_QUEUE_OPTIONS="--sleep=3 --tries=3" \
|
||||
LARAVEL_SCHEDULER_ENABLED=true \
|
||||
PHP_DATE_TIMEZONE=UTC \
|
||||
PHP_DISPLAY_ERRORS=Off \
|
||||
PHP_MEMORY_LIMIT=256M \
|
||||
PHP_UPLOAD_MAX_FILESIZE=30M \
|
||||
PHP_POST_MAX_SIZE=30M \
|
||||
PHP_MAX_EXECUTION_TIME=30 \
|
||||
PHP_OPCACHE_ENABLE=1 \
|
||||
PHP_OPCACHE_ENABLE_CLI=0 \
|
||||
PHP_OPCACHE_MEMORY_CONSUMPTION=512 \
|
||||
PHP_OPCACHE_MAX_ACCELERATED_FILES=50000 \
|
||||
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
|
||||
PHP_OPCACHE_REVALIDATE_FREQ=0 \
|
||||
PHP_FPM_PM=dynamic \
|
||||
PHP_FPM_PM_MAX_CHILDREN=20 \
|
||||
PHP_FPM_PM_START_SERVERS=2 \
|
||||
PHP_FPM_PM_MIN_SPARE_SERVERS=1 \
|
||||
PHP_FPM_PM_MAX_SPARE_SERVERS=3 \
|
||||
PHP_FPM_PM_MAX_REQUESTS=500
|
||||
|
||||
# Runtime tools and Node.js
|
||||
RUN apk add --no-cache bash curl git openssh-client unzip zip supervisor sqlite nano nodejs npm
|
||||
|
||||
# PHP extensions (build dependencies are removed, runtime libraries are kept)
|
||||
RUN set -eux; \
|
||||
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
|
||||
freetype-dev libjpeg-turbo-dev libpng-dev libwebp-dev \
|
||||
icu-dev libmemcached-dev oniguruma-dev libpq-dev librdkafka-dev \
|
||||
libxml2-dev libzip-dev zlib-dev cyrus-sasl-dev linux-headers; \
|
||||
docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp; \
|
||||
docker-php-ext-install -j"$(nproc)" bcmath exif gd intl mbstring pcntl pdo_mysql pdo_pgsql zip; \
|
||||
pecl install redis memcached rdkafka; \
|
||||
docker-php-ext-enable redis memcached rdkafka; \
|
||||
# OPcache is always compiled in since PHP 8.5
|
||||
if ! php -m | grep -qi '^zend opcache$'; then docker-php-ext-install opcache; fi; \
|
||||
runDeps="$( \
|
||||
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
|
||||
| tr ',' '\n' | sort -u \
|
||||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
||||
)"; \
|
||||
apk add --no-cache --virtual .php-ext-rundeps $runDeps; \
|
||||
apk del --no-network .build-deps; \
|
||||
rm -rf /tmp/pear ~/.pearrc; \
|
||||
! php -m 2>&1 | grep -iE 'warning|unable to load'
|
||||
|
||||
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
|
||||
|
||||
# Set working directory
|
||||
WORKDIR $WORKDIR
|
||||
|
||||
RUN rm -Rf /var/www/* && \
|
||||
mkdir -p /var/www/html
|
||||
RUN rm -Rf /var/www/* && mkdir -p ${WORKDIR} /etc/supervisor/conf.d /var/log/supervisor
|
||||
|
||||
ADD src/index.php $WORKDIR/index.php
|
||||
ADD src/php.ini $PHP_INI_DIR/conf.d/
|
||||
COPY src/index.php $WORKDIR/index.php
|
||||
COPY src/php.ini src/opcache.ini $PHP_INI_DIR/conf.d/
|
||||
COPY src/php-fpm.d/zz-laravel.conf /usr/local/etc/php-fpm.d/zz-laravel.conf
|
||||
COPY src/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
|
||||
COPY --chmod=755 src/entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN ln -s /usr/local/bin/entrypoint.sh /entrypoint.sh && \
|
||||
ln -sf /etc/supervisor/supervisord.conf /etc/supervisord.conf
|
||||
|
||||
RUN apk add --no-cache --virtual .user-deps shadow && \
|
||||
usermod -u ${USER_ID} ${USER_NAME} && \
|
||||
groupmod -g ${GROUP_ID} ${GROUP_NAME} && \
|
||||
apk del --no-network .user-deps && \
|
||||
chown -R ${USER_NAME}:${GROUP_NAME} /var/www /var/log /etc/supervisor/conf.d $PHP_INI_DIR/conf.d /tmp
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --start-interval=2s --retries=3 \
|
||||
CMD php -r 'exit(@fsockopen("127.0.0.1", 9000) ? 0 : 1);'
|
||||
|
||||
EXPOSE 9000
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
CMD ["entrypoint"]
|
||||
+52
-23
@@ -1,13 +1,12 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# Logging functions
|
||||
log() {
|
||||
local level=$1
|
||||
level=$1
|
||||
shift
|
||||
{ set +x; } 2> /dev/null
|
||||
echo "[$level] $@"
|
||||
echo "[$level] $*"
|
||||
}
|
||||
|
||||
info() {
|
||||
@@ -23,6 +22,32 @@ fatal() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
is_true() {
|
||||
case "$1" in
|
||||
1|true|TRUE|True|yes|YES|on|ON) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
APP_DIR="${APP_DIR:-/var/www/html}"
|
||||
USER_NAME="${USER_NAME:-www-data}"
|
||||
LARAVEL_PROCS_NUMBER="${LARAVEL_PROCS_NUMBER:-1}"
|
||||
LARAVEL_QUEUE_OPTIONS="${LARAVEL_QUEUE_OPTIONS:---sleep=3 --tries=3}"
|
||||
|
||||
# Check if custom php.ini file exists
|
||||
PHP_INI_SOURCE="$APP_DIR/conf/php/php.ini"
|
||||
PHP_INI_TARGET="$PHP_INI_DIR/conf.d/php.ini"
|
||||
|
||||
if [ -f "$PHP_INI_SOURCE" ]; then
|
||||
cp "$PHP_INI_SOURCE" "$PHP_INI_TARGET"
|
||||
info "Custom php.ini file found and copied to $PHP_INI_TARGET"
|
||||
fi
|
||||
|
||||
# Run any other command (e.g. "php artisan migrate", "composer install", "bash")
|
||||
if [ $# -gt 0 ] && [ "$1" != "entrypoint" ] && [ "$1" != "supervisord" ]; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Banner
|
||||
echo ""
|
||||
echo "***********************************************************"
|
||||
@@ -30,13 +55,14 @@ echo " Starting LARAVEL PHP-FPM Container "
|
||||
echo "***********************************************************"
|
||||
|
||||
# Check if the artisan file exists
|
||||
ARTISAN_PATH="/var/www/html/artisan"
|
||||
if [[ -f "$ARTISAN_PATH" ]]; then
|
||||
ARTISAN_PATH="$APP_DIR/artisan"
|
||||
SUPERVISOR_TASK="/etc/supervisor/conf.d/laravel-worker.conf"
|
||||
if [ -f "$ARTISAN_PATH" ]; then
|
||||
info "Artisan file found, creating Laravel supervisor config..."
|
||||
: > "$SUPERVISOR_TASK"
|
||||
|
||||
# Create Laravel Supervisor config
|
||||
SUPERVISOR_TASK="/etc/supervisor/conf.d/laravel-worker.conf"
|
||||
cat > "$SUPERVISOR_TASK" <<EOF
|
||||
if is_true "${LARAVEL_SCHEDULER_ENABLED:-true}"; then
|
||||
cat >> "$SUPERVISOR_TASK" <<EOF
|
||||
[program:Laravel-scheduler]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=/bin/sh -c "while true; do php $ARTISAN_PATH schedule:run --verbose --no-interaction & sleep 60; done"
|
||||
@@ -47,33 +73,36 @@ user=$USER_NAME
|
||||
stdout_logfile=/var/log/laravel_scheduler.out.log
|
||||
redirect_stderr=true
|
||||
|
||||
EOF
|
||||
info "Laravel scheduler enabled"
|
||||
fi
|
||||
|
||||
if is_true "${LARAVEL_QUEUE_WORKER_ENABLED:-true}"; then
|
||||
cat >> "$SUPERVISOR_TASK" <<EOF
|
||||
[program:Laravel-worker]
|
||||
process_name=%(program_name)s_%(process_num)02d
|
||||
command=php $ARTISAN_PATH queue:work --sleep=3 --tries=3
|
||||
command=php $ARTISAN_PATH queue:work $LARAVEL_QUEUE_OPTIONS
|
||||
autostart=true
|
||||
autorestart=true
|
||||
; Keep retrying while the database/queue backend is not ready yet
|
||||
startretries=20
|
||||
stopwaitsecs=3600
|
||||
numprocs=$LARAVEL_PROCS_NUMBER
|
||||
user=$USER_NAME
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/laravel_worker.log
|
||||
EOF
|
||||
info "Laravel queue worker enabled ($LARAVEL_PROCS_NUMBER process(es))"
|
||||
fi
|
||||
|
||||
info "Laravel supervisor config created at $SUPERVISOR_TASK"
|
||||
else
|
||||
rm -f "$SUPERVISOR_TASK" 2>/dev/null || true
|
||||
info "Artisan file not found at $ARTISAN_PATH"
|
||||
fi
|
||||
|
||||
# Check if custom php.ini file exists
|
||||
PHP_INI_SOURCE="/var/www/html/conf/php/php.ini"
|
||||
PHP_INI_TARGET="$PHP_INI_DIR/conf.d/php.ini"
|
||||
|
||||
if [[ -f "$PHP_INI_SOURCE" ]]; then
|
||||
cp "$PHP_INI_SOURCE" "$PHP_INI_TARGET"
|
||||
info "Custom php.ini file found and copied to $PHP_INI_TARGET"
|
||||
else
|
||||
info "Custom php.ini file not found at $PHP_INI_SOURCE"
|
||||
info "To use a custom php.ini file, place it at $PHP_INI_SOURCE"
|
||||
# Start Supervisor (programs drop privileges to $USER_NAME themselves)
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
exec supervisord -c /etc/supervisor/supervisord.conf -u root
|
||||
fi
|
||||
|
||||
# Start Supervisor
|
||||
supervisord -c /etc/supervisor/supervisord.conf
|
||||
exec supervisord -c /etc/supervisor/supervisord.conf
|
||||
+8
-12
@@ -1,12 +1,12 @@
|
||||
[opcache]
|
||||
; Determines if Zend OPCache is enabled
|
||||
opcache.enable=1
|
||||
opcache.enable=${PHP_OPCACHE_ENABLE}
|
||||
|
||||
; Determines if Zend OPCache is enabled for the CLI version of PHP
|
||||
;opcache.enable_cli=1
|
||||
opcache.enable_cli=${PHP_OPCACHE_ENABLE_CLI}
|
||||
|
||||
; The OPcache shared memory storage size.
|
||||
opcache.memory_consumption=512
|
||||
opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}
|
||||
|
||||
; The amount of memory for interned strings in Mbytes.
|
||||
opcache.interned_strings_buffer=64
|
||||
@@ -15,7 +15,7 @@ opcache.interned_strings_buffer=64
|
||||
; Only numbers between 200 and 1000000 are allowed.
|
||||
;If you have multiple PHP sites on the server then consider the value 130986
|
||||
; for magento 2, keep 65406
|
||||
opcache.max_accelerated_files=50000
|
||||
opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}
|
||||
|
||||
; The maximum percentage of "wasted" memory until a restart is scheduled.
|
||||
opcache.max_wasted_percentage=15
|
||||
@@ -30,7 +30,7 @@ opcache.max_wasted_percentage=15
|
||||
; webserver for changes to the filesystem to take effect.
|
||||
; For Development / testing, keep 1
|
||||
; For performance / production, keep 0
|
||||
opcache.validate_timestamps=0
|
||||
opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}
|
||||
|
||||
;opcache.revalidate_freq How often in seconds should the code
|
||||
;cache expire and check if your code has changed. 0 means it
|
||||
@@ -39,7 +39,7 @@ opcache.validate_timestamps=0
|
||||
;should not be enabled by default, as long as it's disabled then any value for opcache.
|
||||
;revalidate_freq will basically be ignored. You should really only ever enable
|
||||
;this during development, you don't really want to enable this setting for a production application.
|
||||
opcache.revalidate_freq=0
|
||||
opcache.revalidate_freq=${PHP_OPCACHE_REVALIDATE_FREQ}
|
||||
|
||||
; Enables or disables file search in include_path optimization
|
||||
;opcache.revalidate_path=0
|
||||
@@ -48,10 +48,6 @@ opcache.revalidate_freq=0
|
||||
; size of the optimized code.
|
||||
opcache.save_comments=1
|
||||
|
||||
; If enabled, a fast shutdown sequence is used for the accelerated code
|
||||
; Depending on the used Memory Manager this may cause some incompatibilities.
|
||||
opcache.fast_shutdown=1
|
||||
|
||||
; Allow file existence override (file_exists, etc.) performance feature.
|
||||
;opcache.enable_file_override=0
|
||||
|
||||
@@ -106,7 +102,7 @@ opcache.fast_shutdown=1
|
||||
; processes have to map shared memory into the same address space. This
|
||||
; directive allows to manually fix the "Unable to reattach to base address"
|
||||
; errors.
|
||||
opcache.mmap_base=0x20000000
|
||||
;opcache.mmap_base=
|
||||
|
||||
; Enables and sets the second level cache directory.
|
||||
; It should improve performance when SHM memory is full, at server restart or
|
||||
@@ -122,7 +118,7 @@ opcache.mmap_base=0x20000000
|
||||
; Implies opcache.file_cache_only=1 for a certain process that failed to
|
||||
; reattach to the shared memory (for Windows only). Explicitly enabled file
|
||||
; cache is required.
|
||||
opcache.file_cache_fallback=1
|
||||
;opcache.file_cache_fallback=1
|
||||
|
||||
; Enables or disables copying of PHP code (text segment) into HUGE PAGES.
|
||||
; This should improve performance, but requires appropriate OS configuration.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[www]
|
||||
; Expose container environment variables (DB_HOST, APP_KEY, ...) to PHP workers
|
||||
clear_env = no
|
||||
|
||||
; Process manager, tunable through PHP_FPM_* environment variables
|
||||
pm = ${PHP_FPM_PM}
|
||||
pm.max_children = ${PHP_FPM_PM_MAX_CHILDREN}
|
||||
pm.start_servers = ${PHP_FPM_PM_START_SERVERS}
|
||||
pm.min_spare_servers = ${PHP_FPM_PM_MIN_SPARE_SERVERS}
|
||||
pm.max_spare_servers = ${PHP_FPM_PM_MAX_SPARE_SERVERS}
|
||||
pm.max_requests = ${PHP_FPM_PM_MAX_REQUESTS}
|
||||
|
||||
; Health endpoint for FastCGI probes
|
||||
ping.path = /ping
|
||||
ping.response = pong
|
||||
+8
-5
@@ -1,6 +1,9 @@
|
||||
date.timezone=UTC
|
||||
display_errors=Off
|
||||
; Values can be overridden with environment variables (see README)
|
||||
date.timezone=${PHP_DATE_TIMEZONE}
|
||||
display_errors=${PHP_DISPLAY_ERRORS}
|
||||
log_errors=On
|
||||
upload_max_filesize= 30M
|
||||
post_max_size= 30M
|
||||
memory_limit = 256M
|
||||
expose_php=Off
|
||||
upload_max_filesize=${PHP_UPLOAD_MAX_FILESIZE}
|
||||
post_max_size=${PHP_POST_MAX_SIZE}
|
||||
memory_limit=${PHP_MEMORY_LIMIT}
|
||||
max_execution_time=${PHP_MAX_EXECUTION_TIME}
|
||||
@@ -1,23 +1,31 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=%(ENV_USER_NAME)s
|
||||
logfile=/var/log/supervisor/supervisord.log
|
||||
logfile_maxbytes = 50MB
|
||||
pidfile=/tmp/supervisord.pid
|
||||
directory = /tmp
|
||||
|
||||
[unix_http_server]
|
||||
file=/tmp/supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///tmp/supervisor.sock
|
||||
|
||||
[program:php-fpm]
|
||||
command=/usr/local/sbin/php-fpm
|
||||
command=/usr/local/sbin/php-fpm --nodaemonize
|
||||
numprocs=1
|
||||
autostart=true
|
||||
autorestart=true
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/dev/stdout
|
||||
stderr_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
user=www-data
|
||||
priority=1
|
||||
stopsignal=QUIT
|
||||
|
||||
|
||||
[include]
|
||||
files = /etc/supervisor/conf.d/*.conf
|
||||
files = /etc/supervisor/conf.d/*.conf
|
||||
Reference in new issue
Block a user