Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📦 Simplified PHP Docker images for effortless customization and extension setup. Our Docker images cover PHP versions from 5.6 to 8.4, available in CLI, ZTS, FPM, FPM/Apache2, FPM/Nginx, RoadRunner, FrankenPHP, and Nginx Unit variants, for both Debian and Alpine versions. Build everyday.

License

NotificationsYou must be signed in to change notification settings

shinsenter/php

Repository files navigation

📦 Simplified PHP Docker images for effortless customization and extension setup.

Our Docker images cover PHP versions from 5.6 to 8.4, available in CLI, ZTS, FPM, FPM/Apache2, FPM/Nginx, RoadRunner, FrankenPHP, and Nginx Unit variants. The Docker images are available for both Debian and Alpine versions.

Daily build

Introduction

shinsenter/php

Our PHP Docker images are based on theofficial PHP Docker images.These images facilitate the easy adjustment of PHP and PHP-FPM settings using environment variables,eliminating the need to rebuild images when making configuration changes.

These images also come with the latest version ofComposerand popular web servers likeApache2,Nginx,RoadRunner,FrankenPHP orNginx Unit.This setup allows for faster project initiation without additional installations.

🪶 Info: While built on the official PHP images and including more useful extensions,we havesignificantly reduced the image sizes compared to the base images.This optimization improves download times and resource usage without sacrificing functionality,thanks to thedocker-squash project.

Docker Image Variants

Our image tags cover PHP versions from 5.6 to 8.4,available incli,zts,fpm,fpm-nginx,fpm-apache,roadrunner(1),frankenphp(2), andunit-php(3) variants. The Docker images are available for both Debian and Alpine versions.

Examples:

  • shinsenter/php:7.2-cli
  • shinsenter/php:7.3-zts
  • shinsenter/php:7.4-fpm
  • shinsenter/php:8.0-fpm-apache
  • shinsenter/php:8.1-fpm-nginx
  • shinsenter/php:8.2-roadrunner(1)
  • shinsenter/php:8.3-frankenphp(2)
  • shinsenter/php:8.4-unit-php(3)

(1): PHP with RoadRunner server. Theroadrunner variant supports PHP >= 8.0.
(2): FrankenPHP is still in BETA. Thefrankenphp variant supports PHP >= 8.2.
(3): PHP with Nginx Unit server. Theunit-php variant supports PHP >= 7.4.

Explore all available tags on ourDocker Hub.

For stable versions suitable for production, we also offer version tags onanother repository.

Examples

You can easily run a container by copying and pasting one of thesedocker run commands:

CLI

# non-interactivedocker run --rm shinsenter/php:8.4-cli php -m# interactivedocker run -it -v ./myproject:/var/www/html shinsenter/php:8.4-cli

PHP-FPM

docker run -v ./myproject:/var/www/html -p 9000:9000 shinsenter/php:8.4-fpm

PHP-FPM + Nginx (or Apache, RoadRunner, FrankenPHP, Nginx Unit)

# with Nginxdocker run -v ./myproject:/var/www/html -p 80:80 -p 443:443 shinsenter/php:8.4-fpm-nginx# with Apachedocker run -v ./myproject:/var/www/html -p 80:80 -p 443:443 shinsenter/php:8.4-fpm-apache# with RoadRunnerdocker run -v ./myproject:/var/www/html -p 80:80 -p 443:443 shinsenter/php:8.3-roadrunner# with FrankenPHPdocker run -v ./myproject:/var/www/html -p 80:80 -p 443:443 shinsenter/php:8.3-frankenphp# with Nginx Unitdocker run -v ./myproject:/var/www/html -p 80:80 -p 443:443 shinsenter/php:8.3-unit-php

Customizing Settings via Environment Variables

These images allow customizing PHP and PHP-FPM settings through environment variables instead of rebuilding images.

The environment variable names follow these conventions:

This naming convention helps you easily identify which environment variable applies to which PHP/PHP-FPM configuration directive.

👉🏻 Info: By default, the$PHP_* environment variables only take effect when set before starting the container.To dynamically change PHP configurations using$PHP_* environment variables while running commands within the container,you need to start your container with theALLOW_RUNTIME_PHP_ENVVARS=1 environment variable.

💡 Hint: Runphp-envvars in the container to get a full list of default$PHP_* environment variables.

Examples

Command Line

docker run \    -v ./myproject:/var/www/html \    -e PHP_DISPLAY_ERRORS='1' \    -e PHP_POST_MAX_SIZE='100M' \    -e PHP_UPLOAD_MAX_FILESIZE='100M' \    -e PHP_SESSION_COOKIE_HTTPONLY='1' \    shinsenter/php:8.4 php -i

With docker-compose.yml

services:web:image:shinsenter/php:8.4-fpm-nginxenvironment:PHP_DISPLAY_ERRORS:"1"PHP_POST_MAX_SIZE:"100M"PHP_UPLOAD_MAX_FILESIZE:"100M"PHP_SESSION_COOKIE_HTTPONLY:"1"

Explanation

Environment VariableExplanationEquivalent Configuration
PHP_DISPLAY_ERRORS=1Enables displaying errors during development.display_errors 1
PHP_POST_MAX_SIZE=100MIncreases the maximum post size from the default 8MB.post_max_size 100M
PHP_UPLOAD_MAX_FILESIZE=100MIncreases the maximum upload file size from the default 2MB.upload_max_filesize 100M
PHP_SESSION_COOKIE_HTTPONLY=1Enables the HttpOnly flag for session cookie security.session.cookie_httponly 1

💡 Hint: Runphp-envvars in the container to get a full list of default$PHP_* environment variables.

Pre-installed PHP Extensions

Popular PHP extensions are pre-installed by default, allowing projects to get started faster without additional installation.

apcubcmathcalendarexifgdgettextigbinaryintlmsgpackmysqliopcachepcntlpdo_mysqlpdo_pgsqlredissodiumuuidyamlzip

👉🏻 Info: The pre-installed PHP extensions from the official Docker images are excluded from this list.

💡 Hint: Rundocker run --rm shinsenter/php:8.4-cli php -m in the containerto get a list of extensions (you can replace8.4 with a specific PHP version).

Adding PHP Extensions

These images use a simple command calledphpaddmod to install PHP extensions.

You don't need to run the more complexdocker-php-ext-install commandor manually edit thephp.ini file;phpaddmod handles the installation and configuration for you.

For example, in yourDockerfile:

FROM shinsenter/php:8.4-fpm-nginx# Install imagick, swoole and xdebugRUN phpaddmod imagick swoole xdebug# Add your instructions here# For example:# ADD --chown=$APP_USER:$APP_GROUP ./myproject/ /var/www/html/

👉🏻 Info: Thephpaddmod command is a wrapper around themlocati/docker-php-extension-installer utility,which takes care of all required steps to compile and activate the extensions.

💡 Hint: If you're having trouble figuring out which extensions can be installed,have a look attheir documentation.

Application Directory

The default application directory is/var/www/html and can be customized via the$APP_PATH environment variable:

docker run -p 80:80 -p 443:443 -p 443:443/udp \    -v"$PWD":/app \    -e APP_PATH=/app \    shinsenter/php:8.4-fpm-nginx

This changes the web application directory to/app.

Moreover, the default document root(a relative path inside the application directory that contains yourindex.php file)can be customized by setting the$DOCUMENT_ROOT environment variable:

docker run -p 80:80 -p 443:443 -p 443:443/udp \    -v"$PWD":/app \    -e APP_PATH=/app \    -e DOCUMENT_ROOT=/public \    shinsenter/php:8.4-fpm-nginx

This would change the document root path to/app/public.

Customizing Container User and Group in Docker

Override the default user and group settings by setting environment variables when running the container.

Available variables:

Environment VariableDescriptionDefault
APP_USERUsername inside the containerwww-data
APP_GROUPGroup name inside the containerwww-data
APP_UIDNumeric UID of the userUID in container
APP_GIDNumeric GID of the groupGID in container

For example, to run a container as usermyapp with UID5000:

docker run -p 80:80 -p 443:443 -p 443:443/udp \    -e APP_USER=myapp \    -e APP_UID=5000 \    shinsenter/php:8.4-fpm-nginx

Or in adocker-compose.yml:

services:web:image:shinsenter/php:8.4-fpm-nginxenvironment:APP_USER:"myapp"APP_UID:"5000"

Autorun Scripts

Shell scripts placed in the/startup/ directory will automatically run when the container starts, in alphabetical order by filename.This feature can initialize projects before the main program runs, saving time by executing initialization scripts automatically.

Usage Example

Copy a script called00-migration into/startup/ via a Dockerfile:

Note: Ensure the script has executable permissions.

FROM shinsenter/php:8.4-cliADD ./autorun/00-migration /startup/00-migrationRUN chmod +x /startup/00-migration# Add your instructions here# For example:# ADD --chown=$APP_USER:$APP_GROUP ./myproject/ /var/www/html/

👉🏻 Info: The startup directory already includes a script called99-greeting that prints a welcome message when the container starts.

░█▀▀░█░█░▀█▀░█▀█░█▀▀░█▀▀░█▀█░▀█▀░█▀▀░█▀▄░░░█░█▀█░█░█░█▀█░▀▀█░█▀█░░█░░█░█░▀▀█░█▀▀░█░█░░█░░█▀▀░█▀▄░▄▀░░█▀▀░█▀█░█▀▀░▀▀▀░▀░▀░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀░▀░░▀░░▀▀▀░▀░▀░▀░░░▀░░░▀░▀░▀░░If you find my Docker images useful, consider donating via PayPal: -> https://www.paypal.me/shinsenter(To edit this welcome message, add your text to /etc/welcome.txt)---------------Container     : shinsenter/php (built: 2024-11-22T00:00:00+0000)Distro        : Debian GNU/Linux 12 (bookworm)Timezone      : UTC (GMT+0000)UID / GID     : www-data:www-data (33:33)App Root      : /var/www/htmlDocument Root : /var/www/html---------------Docker Images by SHIN CompanyCopyright (C) 2024 SHIN Company <shin@shin.company>This software is free under the GNU General Public License (GPL).You can redistribute and/or modify it under the terms of the GNU GPL.This program is provided with the hope that it will be useful,but it comes WITHOUT ANY WARRANTY. For more details, refer to the GNU GPL.To get support, please contact: SHIN Company <shin@shin.company>Docker Hub:      https://hub.docker.com/u/shinsenterGitHub Packages: https://github.com/shinsenter?tab=packagesPHP 8.4.1 (cli) (built: Nov 21 2024 17:55:46) (NTS)Copyright (c) The PHP GroupBuilt by https://github.com/docker-library/phpZend Engine v4.4.1, Copyright (c) Zend Technologies    with Zend OPcache v8.4.1, Copyright (c), by Zend TechnologiesComposer version 2.8.3 2024-11-17 13:13:04

Disable Autorun Scripts

To disable autorun scripts, setDISABLE_AUTORUN_SCRIPTS=1 as an environment variable.

For example, withdocker run:

docker run -e DISABLE_AUTORUN_SCRIPTS=1 shinsenter/ubuntu-s6:latest bash

Or indocker-compose.yml:

services:web:image:shinsenter/ubuntu-s6:latestenvironment:DISABLE_AUTORUN_SCRIPTS:"1"

Using Cron Jobs

To enable cron jobs in containers, you can start the container withENABLE_CRONTAB=1.This setting activates the Crontab service, which loads settings from the directory specified by$CRONTAB_DIR (default is/etc/crontab.d).

The cron jobs will run as the user defined by$APP_USER:$APP_GROUP, which by default iswww-data:www-data,and with the home directory set by$CRONTAB_HOME (default is/var/www/html).

Here is an example Dockerfile to add a crontab:

FROM shinsenter/php:latestENV ENABLE_CRONTAB=1# create crontab entry via RUN instructionRUN echo'* * * * * echo "echo This line will run every minute!" | tee /tmp/cron-every-minute.txt' >> /etc/crontab.d/sample1;# or copy crontab entries via ADD instructionADD ./sample2 /etc/crontab.d/

The format of a crontab entry is as follows:

# Job definition:# .---------------- minute (0 - 59)# |  .------------- hour (0 - 23)# |  |  .---------- day of month (1 - 31)# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |# *  *  *  *  *  command to be executed

You can also easily set up cron jobs through the$CRONTAB_SETTINGS environment variable in thedocker-compose.yml file.When the container starts, these settings are loaded into crontab, giving you more flexibility to change them later.

services:web:image:shinsenter/php:8.4-fpm-nginxenvironment:ENABLE_CRONTAB:"1"CRONTAB_SETTINGS:"* * * * * echo 'This line will run every minute!' | tee /tmp/cron-every-minute.txt"

For more information on environment variables for cron jobs, refer to theOther System Settings section below.

Customize Supervisor command

We can set a$SUPERVISOR_PHP_COMMAND environment variable to the service definition in your application'sdocker-compose.yml file.This environment variable will contain the command that the container will use to serve your application using another process instead of the default process.

Command Line

docker run \    -e SUPERVISOR_PHP_COMMAND='php -S localhost:80 index.php' \    shinsenter/php:8.4

With docker-compose.yml

services:web:image:shinsenter/php:8.4environment:SUPERVISOR_PHP_COMMAND:"php -S localhost:80 index.php"

Debug Mode

Enable "debug mode" for more verbose logging by settingDEBUG=1 as an environment variable.This can be used both withdocker run and indocker-compose.yml.

Command Line

docker run -e DEBUG=1 shinsenter/php:8.4-fpm-nginx

With docker-compose.yml

services:web:image:shinsenter/php:8.4-fpm-nginxenvironment:DEBUG:"1"

Other System Settings

These Docker images include additional environment variables for fine-tuning container behavior:

Setting NameDefault ValueDescriptionExample
DEFAULT_LOG_PATH/dev/stderrSets the log output path. By default, logs will be sent to the container's standard output./var/log/container.txt
DEBUG orDEBUG_MODENot setActivates debug mode with more verbose logs when set to1.1
TZUTCSets the default timezone for the container.Full list.Asia/Tokyo
ALLOW_RUNTIME_PHP_ENVVARSNot setEnables the use of$PHP_* environment variables to dynamically change configurations when running PHP commands in the container.1
INITIAL_PROJECTNot setSpecifies a project for Composer to create in the application directory when it is empty.
※ If the value is a URL ending in*.zip or*.tar.gz, the container will download and extract the source code to the application directory.
laravel/laravel
DISABLE_AUTORUN_SCRIPTSNot setDisables all autorun scripts when set to1.0
DISABLE_AUTORUN_CREATING_PROJECTNot setPrevents the creation of a new project when set to1. By default, Composer creates a project if$INITIAL_PROJECT is set and the application directory is empty.0
DISABLE_AUTORUN_COMPOSER_INSTALLNot setDisablescomposer install at startup when set to1. By default,composer install runs at startup ifcomposer.json is present but packages are missing.0
DISABLE_AUTORUN_GENERATING_INDEXNot setPrevents the creation ofindex.php when set to1. By default, anindex.php is created in the$DOCUMENT_ROOT directory if it doesn't exist.0
DISABLE_AUTORUN_FIX_OWNER_GROUPNot setDisables automatic ownership correction of the application directory when set to "1".1
DISABLE_GREETINGNot setDisables the welcome message at container startup when set to1.0
ENABLE_CRONTABNot setEnables the Crontab service when set to1, loading settings from the directory defined by$CRONTAB_DIR (default is/etc/crontab.d).1
CRONTAB_DIR/etc/crontab.dSpecifies the directory containing cron job settings. Cron jobs are run as the user defined by$APP_USER./path/for/crontab/schedules
CRONTAB_HOME$APP_PATHSpecifies the$HOME directory for cron jobs./path/for/crontab
CRONTAB_MAILTONot setEmail address to which cron job logs are sent.admin@example.com
CRONTAB_PATH$PATHSets the directory paths for executing cron jobs./path/for/crontab/bin
CRONTAB_SETTINGSNot setAllows you to configure cron jobs directly in the docker-compose.yml file, making it easy to manage and update scheduled tasks within your Docker container.0 0 * * * echo "Hello new day!"
CRONTAB_SHELL/bin/shSets the default shell for cron jobs./bin/bash
CRONTAB_TZ$TZSets the default timezone for cron jobs.Full list.Asia/Tokyo
SUPERVISOR_PHP_COMMANDNot setContains the command that the container will use to serve your application instead of the default entrypoint command.php -S localhost:80 index.php
ENABLE_TUNING_FPMNot enabledEnables auto-tuning of PM control settings when set to1.0
ENABLE_TUNING_MPMNot enabledEnables auto-tuning of Apache MPM settings when set to1.0

Supported Platforms

Check ourDocker Hub for all available platforms. The Docker images are available for both Debian and Alpine versions.

Stable Image Tags

The release versions onthis GitHub repository don't guaranteethat Docker images built from the same source code will always be identical.

We build new Docker images daily to ensure they stay up-to-datewith the latest upstream updates for PHP, base OS, Composer, etc.The images in this repo are regularly updated under the same tag names.

For stable versions you can depend on in production,we also apply version tags on another repository.

👉🏻 View Stable Tags:https://hub.docker.com/r/shinsenter/php-archives/tags

This way, you get frequently updated images under static tags,providing both the latest code and production stability.

Contributing

If you find these images useful, consider donating viaPayPalor opening an issue onGitHub.

Your support helps maintain and improve these images for the community.

License

This project is licensed under the terms of theGNU General Public License v3.0.

Please respect the intellectual efforts involved in creating these images.If you intend to copy or use ideas from this project, proper credit is appreciated.


From Vietnam 🇻🇳 with love.

About

📦 Simplified PHP Docker images for effortless customization and extension setup. Our Docker images cover PHP versions from 5.6 to 8.4, available in CLI, ZTS, FPM, FPM/Apache2, FPM/Nginx, RoadRunner, FrankenPHP, and Nginx Unit variants, for both Debian and Alpine versions. Build everyday.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp