erseco/alpine-php-webserver

By erseco

Updated 27 days ago

Docker image with Nginx & PHP-FPM on Alpine Linux

Image
Web servers
9

100K+

erseco/alpine-php-webserver repository overview

Alpine PHP Webserver

Docker Pulls Docker Image Size alpine 3.24 nginx 1.28 php 8.5 License MIT

A minimal Nginx + PHP-FPM Docker image built on Alpine Linux — ~25 MB, multi-arch, configured entirely through environment variables.

The documentation site covers quick start, Docker Compose recipes, Nginx/PHP configuration, reverse proxy and trusted-IP setups (Traefik, Nginx, Cloudflare, Cloudflare Tunnel), a complete environment variable reference, Composer/build recipes, how to extend the image with runit daemons and init scripts, the healthcheck and logging story, and a troubleshooting section built from the most frequent support questions.

Quick start

docker run --rm -p 8080:8080 erseco/alpine-php-webserver

Open http://localhost:8080/ to see phpinfo(), or http://localhost:8080/test.html for the static probe.

Mount your own code:

docker run --rm -p 8080:8080 -v "$PWD/php:/var/www/html" erseco/alpine-php-webserver

Compose:

services:
  web:
    image: erseco/alpine-php-webserver
    ports:
      - "8080:8080"
    volumes:
      - ./php:/var/www/html
    restart: unless-stopped

Note: The main branch (Dockerfile) is automatically pushed with the tag beta. Use this tag for testing purposes before stable releases are published.

Key features

  • Compact image (~25 MB) built on Alpine Linux
  • PHP 8.5 FPM with ondemand process manager — idles near-zero CPU
  • Unix-socket FastCGI between Nginx and PHP-FPM
  • Healthcheck on /fpm-ping (localhost-only by design)
  • Trusted-proxy real IP support (REAL_IP_FROM, Cloudflare, Tunnel)
  • DISABLE_DEFAULT_LOCATION for full routing control
  • Custom Nginx snippets via /etc/nginx/conf.d/ and /etc/nginx/server-conf.d/
  • Custom PHP settings via environment variables or /etc/php85/conf.d/*.ini
  • Extra daemons via runit (/etc/service/<name>/run)
  • Startup scripts via /docker-entrypoint-init.d/
  • Non-privileged nobody user; logs on stdout / stderr
  • Multi-arch: amd64, arm64, arm/v7, arm/v6, 386, ppc64le, s390x

Running Commands as Root

The container runs as nobody. When you need root (installing extra Alpine packages for debugging, inspecting file ownership, etc.), use docker compose exec with --user root:

docker compose exec --user root web sh

Example — install debug tools on a running container:

docker compose exec --user root web sh -c "apk update && apk add nano curl htop"

Environment Variables

The most-requested reference. The full grouped reference (with OPcache, real IP, reverse proxy recipes) lives at https://erseco.github.io/alpine-php-webserver/environment-variables/.

ServerVariable NameDefaultDescription
NGINXnginx_root_directory/var/www/htmlDocument root for the default server block.
NGINXclient_max_body_size2MMax allowed client request body.
NGINXfastcgi_read_timeout60sMax time waiting for a response from PHP-FPM.
NGINXfastcgi_send_timeout60sMax time transmitting a request to PHP-FPM.
NGINXDISABLE_DEFAULT_LOCATIONfalseWhen true, comments out the default location / block so you can mount your own via /etc/nginx/server-conf.d/.
NGINXREAL_IP_HEADERX-Forwarded-ForHeader Nginx trusts as the real client IP (X-Forwarded-For, CF-Connecting-IP, …).
NGINXREAL_IP_RECURSIVEoffon to walk the trusted proxy chain recursively.
NGINXREAL_IP_FROM(empty)Comma-separated list of trusted proxy IPs / CIDRs. Real IP stays disabled until set.
PHP8clear_envnoKeep env vars available to FPM workers.
PHP8allow_url_fopenOnEnable URL-aware fopen wrappers.
PHP8allow_url_includeOffAllow include() / require() from URLs.
PHP8display_errorsOffRender errors in HTTP responses.
PHP8file_uploadsOnEnable HTTP uploads.
PHP8max_execution_time0Max script runtime in seconds. 0 = unlimited.
PHP8max_input_time-1Max input parsing time in seconds. -1 = unlimited.
PHP8max_input_vars1000Max POST/GET variables per request.
PHP8memory_limit128MPer-request memory ceiling. -1 = unlimited.
PHP8post_max_size8MMax POST body. Must exceed upload_max_filesize.
PHP8upload_max_filesize2MMax individual file upload size.
PHP8zlib_output_compressionOnTransparent output compression.
PHP8date_timezoneUTCPHP date.timezone.
PHP8intl_default_localeen_USPHP intl.default_locale.
PHP8opcache_enable01 to enable OPcache.
PHP8opcache_memory_consumption256Shared memory in MB.
PHP8opcache_max_accelerated_files20000Max cached files.
PHP8opcache_validate_timestamps00 = production (restart on deploy); 1 = development.
PHP8opcache_preload(empty)Preload script path.
PHP8realpath_cache_size4096KRealpath cache size.
PHP8realpath_cache_ttl600Realpath cache TTL in seconds.

Registries

  • Docker Hub: erseco/alpine-php-webserver
  • GitHub Container Registry: ghcr.io/erseco/alpine-php-webserver

Documentation

The full, searchable documentation lives at https://erseco.github.io/alpine-php-webserver/:

Contributing

Issues and pull requests are welcome: https://github.com/erseco/alpine-php-webserver/issues.

Documentation sources live under docs/ and are built with Zensical via the docs.yml GitHub Actions workflow.

License

MIT

Tag summary

Content type

Image

Digest

sha256:db38817b3

Size

29.9 MB

Last updated

27 days ago

docker pull erseco/alpine-php-webserver:beta