Sign inSign up

antonmatyunin/php-worker

By antonmatyunin

•Updated over 3 years ago

Base php image with minimal handlers

Image
Languages & frameworks
Web servers
0

151

antonmatyunin/php-worker repository overview

⁠Intro

Base images for php

⁠Features

  • ENV variables for the most used options (have the max priority)
  • Can be used alongside with mounted (or copied) configs
  • SSH daemon. Can be enabled by SSH_ENABLED variable

⁠Environment variables

Some php settings can be set via PHP_* and OPCACHE_* environment variables. Another php settings can be set via mounting config inside container (will be explained below)

ENV ROOT_DIR=/var/www/html \
    WEB_USER_NAME=www \
    WEB_USER_ID=1000 \
    WEB_GROUP_NAME=web-server \
    WEB_GROUP_ID=1000 \
    WEB_USER_HOME_DIR=/var/www/ \
    WEB_USER_PASSWORD='pass77ja'\
    SSH_ENABLED=true \
    SSH_PORT=22023 \
    PHP_RUN_USER=www-data \
    PHP_FILE_UPLOADS=On \
    PHP_MAX_UPLOAD_FILESIZE=30M \
    PHP_POST_MAX_SIZE=30M \
    PHP_MEMORY_LIMIT=512M \
    PHP_LISTEN_PORT=9000 \
    PHP_PM=dynamic \
    PHP_MAX_CHILDREN=15 \
    PHP_START_SERVERS=7 \
    PHP_MIN_SPARE_SERVERS=3 \
    PHP_MAX_SPARE_SERVERS=14 \
    PHP_MAX_REQUESTS=498 \
    PHP_DISPLAY_ERRORS=off \
    PHP_DISPLAY_STARTUP_ERRORS=off \
    PHP_ERROR_REPORTING='E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR' \
    PHP_LOG_ERRORS=On \
    PHP_FPM_ERROR_LOG=/proc/1/fd/1 \
    PHP_LOG_ERRORS_MAX_LEN=1024 \
    PHP_IGNORE_REPEATED_ERRORS=On \
    PHP_IGNORE_REPEATED_SOURCE=Off \
    PHP_HTML_ERRORS=Off \
    PHP_FPM_ACCESS_LOG=/proc/1/fd/1 \
    PHP_FPM_ACCESS_FORMAT='"%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"' \
    OPCACHE_ENABLE=1 \
    OPCACHE_ENABLE_CLI=0 \
    OPCACHE_REVALIDATE_FREQ=2 \
    OPCACHE_MAX_ACCELERATED_FILES=4000 \
    OPCACHE_INTERNED_STRINGS_BUFFER=8 \
    OPCACHE_MEMORY_CONSUMPTION=128 \
    OPCACHE_FAST_SHUTDOWN=1

⁠How to use

  • build you own image or use this as is
  • set environment variables as you need
  • if you want to use SSH inside container you should set SSH_ENABLED=yes and change $WEB_USER_PASSWORD to something yours.
  • image contains default configs. If you need, you can override them by you own. Please note, environment variables, that mentioned before, have max priority
  • mount php code into $ROOT_DIR or COPY it inside the image
  • you can put your own startup scripts into the directory ./startup_scripts/. Please note, this scripts must have .sh extension

⁠Examples

⁠Build your own docker image

cat << 'EOF' > Dockerfile
FROM antonmatyunin/php-worker:7.3-fpm

ENV WEB_USER_NAME=asgard \
    WEB_USER_ID=1002 \
    WEB_GROUP_ID=101 \
    WEB_USER_HOME_DIR=/var/www/asgard-ksm.com.ua \
    SSH_ENABLED=true \
    SSH_PORT=22222 \
    PHP_DISPLAY_ERRORS=on \
    PHP_MEMORY_LIMIT=512M \
    ROOT_DIR=/var/www/asgard-ksm.com.ua/html

RUN apt-get update && \
    apt-get install -y --no-install-recommends git mariadb-client rsync curl && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/asgard-ksm.com.ua
EOF
docker build -t asgard-php:stable .

⁠Create systemd service

# Create your own config for php (please check "Environment variables" section before)
mkdir -p /etc/php/conf.d/ 
mkdir -p /etc/php/php-fpm.d/
touch /etc/php/conf.d/99-asgard.ini
touch /etc/php/php-fpm.d/99-custom.conf

# Create env file
cat << 'EOF' > /etc/default/asgard-php
WEB_USER_PASSWORD=mySuperStrongPassword
EOF

# Create service file for systemd
cat << 'EOF' > /etc/systemd/system/asgard-php.service
[Unit]
Description=PHP server for asgard
Requires=docker.service
After=docker.service
[Install]
WantedBy=multi-user.target
[Service]
EnvironmentFile=/etc/default/asgard-php
ExecStartPre=-/usr/bin/docker kill %p
ExecStartPre=-/usr/bin/docker rm -v %p
ExecStart=/usr/bin/docker run --rm --name %p \
    --hostname asgard-ksm.com.ua \
    --restart no \
    --network=host \
    -v /var/www/asgard-ksm.com.ua:/var/www/asgard-ksm.com.ua \
    -v /etc/php/conf.d/:/usr/local/etc/php/conf.d/ \
    -v /etc/php/php-fpm.d/:/usr/local/etc/php-fpm.d/ \
    -e WEB_USER_PASSWORD=${WEB_USER_PASSWORD} \
    asgard-php:stable
ExecStop=-/bin/docker stop -t 30 %p
RestartSec=10s
TimeoutSec=300
Restart=always
EOF

systemctl enable asgard-php
systemctl start asgard-php

Tag summary

Content type

Image

Digest

sha256:4b454cbdd…

Size

194.1 MB

Last updated

over 3 years ago

docker pull antonmatyunin/php-worker:8.2-fpm