Skip to content

Repository files navigation

Docker PHP

Optimized PHP Docker images with Apache Event MPM and PHP-FPM for high-performance web applications.

Features

  • Apache Event MPM + PHP-FPM: High-performance architecture with threaded Apache and FastCGI process manager
  • Supervisor: Process orchestration for Apache and PHP-FPM
  • PHP Extensions: gd (avif, freetype, jpeg, webp), imagick, intl, mysqli, opcache, pdo_mysql, zip, bcmath, exif, soap
  • Tools: Composer path, msmtp for mail, NewRelic agent
  • Security: Non-root inr user (UID/GID 1000) for PHP-FPM processes
  • Runtime Configuration: Environment-based configuration via gotpl templates

Supported PHP Versions

PHP VersionTag
PHP 8.4inrage/docker-php:8.4
PHP 8.3inrage/docker-php:8.3
PHP 8.2inrage/docker-php:8.2
PHP 8.1inrage/docker-php:8.1

Architecture

Container
|
+-- Supervisor (root)
|
+-- PHP-FPM (priority 10)
| |
| +-- Pool [www] (user: inr)
| +-- Socket: /var/run/php/php-fpm.sock
|
+-- Apache Event MPM (priority 20)
|
+-- proxy_fcgi -> PHP-FPM socket

Quick Start

docker run -d -p 80:80 -v $(pwd):/var/www/html inrage/docker-php:8.4

Environment Variables

Apache Event MPM

VariableDefaultDescription
APACHE_EVENT_START_SERVERS2Number of server processes to start
APACHE_EVENT_MIN_SPARE_THREADS25Minimum number of idle threads
APACHE_EVENT_MAX_SPARE_THREADS75Maximum number of idle threads
APACHE_EVENT_THREADS_PER_CHILD25Number of threads per child process
APACHE_EVENT_THREAD_LIMIT64Maximum threads per child
APACHE_EVENT_MAX_REQUEST_WORKERS150Maximum simultaneous requests
APACHE_EVENT_MAX_CONNECTIONS_PER_CHILD2000Connections before child respawn
APACHE_KEEPALIVEOnEnable HTTP KeepAlive
APACHE_MAX_KEEPALIVE_REQUESTS100Max requests per connection
APACHE_KEEPALIVE_TIMEOUT2KeepAlive timeout in seconds
APACHE_SERVER_NAMElocalhostServer name
APACHE_VHOST_DIR/var/www/htmlDocument root

PHP-FPM Pool

VariableDefaultDescription
PHP_FPM_PMdynamicProcess manager mode (static, dynamic, ondemand)
PHP_FPM_PM_MAX_CHILDREN20Maximum number of child processes
PHP_FPM_PM_START_SERVERS4Number of children at startup
PHP_FPM_PM_MIN_SPARE_SERVERS2Minimum idle children
PHP_FPM_PM_MAX_SPARE_SERVERS6Maximum idle children
PHP_FPM_PM_MAX_REQUESTS500Requests before child respawn

PHP Configuration

VariableDefault
PHP_MEMORY_LIMIT512M
PHP_UPLOAD_MAX_FILESIZE64M
PHP_POST_MAX_SIZE64M
PHP_MAX_EXECUTION_TIME600
PHP_DEFAULT_SOCKET_TIMEOUT60
PHP_SENDMAIL_PATH/usr/bin/msmtp -t --read-envelope-from
PHP_ERROR_REPORTING
PHP_DISPLAY_ERRORSOff
PHP_DISPLAY_STARTUP_ERRORSOff
PHP_LOG_ERRORSOn
PHP_ERROR_LOG/dev/stderr
PHP_LOG_ERRORS_MAX_LEN1024
PHP_IGNORE_REPEATED_ERRORSOn
PHP_IGNORE_REPEATED_SOURCEOff
PHP_HTML_ERRORSOff

OPcache

VariableDefault
PHP_OPCACHE_MEMORY_CONSUMPTION128
PHP_OPCACHE_INTERNED_STRINGS_BUFFER8
PHP_OPCACHE_MAX_ACCELERATED_FILES4000
PHP_OPCACHE_REVALIDATE_FREQ2

MSMTP (Mail)

VariableDefault
INR_SMTP_HOSTrelay.mailhub
INR_SMTP_PORT25
INR_SMTP_TLSoff
INR_SMTP_AUTHoff
INR_SMTP_LOG
INR_SMTP_LOGFILE/proc/self/fd/2
INR_SMTP_ADD_MISSING_DATE_HEADERon

NewRelic

VariableDefaultDescription
NEWRELIC_ENABLEDfalseEnable NewRelic agent
NEWRELIC_LICENSENewRelic license key
NEWRELIC_APPNAMEPHP ApplicationApplication name in NewRelic

Custom Init Scripts

Place shell scripts in /docker-entrypoint-init.d/ to execute them at container startup. Scripts are executed as the inr user.

COPY my-init.sh /docker-entrypoint-init.d/

Build Locally

# Generate all Dockerfiles from templates
./apply-templates.sh
# Build a specific image
docker build -t inrage/docker-php:8.4 latest/php8.4/apache/

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages