Skip to content

PHP CLI Image

Production-grade Docker image for PHP CLI applications: workers, cron jobs, Kafka consumers, deployment scripts. Multi-arch, 20+ extensions, OPcache + JIT, runtime configuration via ENV.

Overview

headgent/phpcli is a multi-stage Alpine image for all PHP processes that don't need a web server. The image includes a complete extension stack (database, messaging, caching, media) and can be configured via 30+ environment variables without rebuilding.

GitHub: jardisOps/phpcli

PropertyValue
PHP versions8.2, 8.3, 8.4
Architectureslinux/amd64, linux/arm64
Image size~142–148 MB (compressed)
BaseAlpine 3.23
Composer2.9.5 (pinned)

Installation

bash
docker pull headgent/phpcli:8.4

Available tags: 8.2, 8.3, 8.4, latest (= 8.4).

Quick Start

yaml
# docker-compose.yml
services:
  worker:
    image: headgent/phpcli:8.4
    volumes:
      - ./:/app
    environment:
      PHP_MEMORY_LIMIT: 256M
      XDEBUG_MODE: "off"
    command: php /app/bin/worker.php

Extensions

Database

ExtensionTypeDescription
pdoBuilt-inPDO abstraction
pdo_mysqlBuilt-inMySQL / MariaDB
mysqliBuilt-inMySQL (procedural)
pdo_pgsqlBuilt-inPostgreSQL

Messaging & Caching

ExtensionTypeVersionDescription
amqpPECL2.2.0RabbitMQ AMQP 0-9-1
rdkafkaPECL6.0.5Apache Kafka client
apcuPECL5.1.28In-memory user cache
redisPECL6.3.0Redis client
opcacheBuilt-inBytecode cache + JIT

Web, I/O & Data

ExtensionTypeDescription
curlBuilt-inHTTP client
soapBuilt-inSOAP web services
socketsBuilt-inNetwork sockets
domBuilt-inXML processing
zipBuilt-inArchive manipulation
mbstringBuilt-inMulti-byte strings
intlBuilt-inInternationalization
bcmathBuilt-inArbitrary precision math

Media & Processes

ExtensionTypeDescription
gdBuilt-inImage generation (FreeType + JPEG)
exifBuilt-inImage metadata
pcntlBuilt-inProcess control (signals)

Debugging & Coverage

ExtensionTypeVersionDescription
xdebugPECL3.5.1Step debugging + profiling
pcovPECL1.0.12Fast code coverage

Configuration

All values are configurable via environment variables, no rebuild required.

PHP Core

VariableDefaultDescription
PHP_MEMORY_LIMIT512MMemory limit
PHP_MAX_EXECUTION_TIME0Max execution time (0 = unlimited)
PHP_TIMEZONEUTCTimezone
PHP_ERROR_REPORTINGE_ALL & ~E_DEPRECATED & ~E_STRICTError reporting level
PHP_DISPLAY_ERRORSOffDisplay errors
PHP_LOG_ERRORSOnLog errors

OPcache & JIT

VariableDefaultDescription
OPCACHE_MEMORY_CONSUMPTION128OPcache memory (MB)
OPCACHE_MAX_ACCELERATED_FILES4000Max cached files
OPCACHE_REVALIDATE_FREQ2Revalidation interval (seconds)
OPCACHE_JIT1254JIT mode (tracing)
OPCACHE_JIT_BUFFER_SIZE128MJIT buffer

APCu

VariableDefaultDescription
APCU_SHM_SIZE64MShared memory size

Xdebug

VariableDefaultDescription
XDEBUG_MODEdebugMode (off, debug, profile, trace, coverage)
XDEBUG_START_WITH_REQUESTyesAuto-start
XDEBUG_CLIENT_HOSThost.docker.internalIDE host
XDEBUG_CLIENT_PORT9003IDE port
XDEBUG_LOG_LEVEL0Log level (0–10)

PCOV

VariableDefaultDescription
PCOV_ENABLED0Enable coverage (0/1)

PCOV vs. Xdebug

When PCOV_ENABLED=1 is set, the entrypoint script automatically disables Xdebug (XDEBUG_MODE=off). PCOV is ~2× faster than Xdebug for code coverage.

Security

  • Non-root execution — container starts as root for UID/GID adaptation, then drops to appuser
  • Automatic UID/GID adaptation — detects mounted /app volume owner and adapts appuser
  • expose_php = Off — PHP version not exposed in HTTP headers
  • Health check — validates PHP and Composer

Build Arguments

For custom builds, these arguments can be passed at build time:

ArgumentDefaultDescription
PHP_VERSION8.3PHP version
ALPINE_VERSION3.23Alpine base
COMPOSER_VERSION2.9.5Composer version
PUID / PGID1000User/group ID
INSTALL_DB_CLIENTS(empty)DB clients: mysql,postgres,sqlite
APCU_VERSION5.1.28PECL version
REDIS_VERSION6.3.0PECL version
XDEBUG_VERSION3.5.1PECL version
PCOV_VERSION1.0.12PECL version
AMQP_VERSION2.2.0PECL version
RDKAFKA_VERSION6.0.5PECL version

Makefile

TargetDescription
make buildLocal build for current PHP_VERSION
make build-allBuild all PHP versions locally
make build-remote-allBuild all versions multi-arch and push
make build-remote-versionBuild one version multi-arch and push
make test-allRun all tests on both architectures
make test-extensionsVerify extensions on both architectures
make test-opcacheVerify OPcache + JIT
make shellInteractive shell in container
make cleanClean up containers, images and cache
make infoShow current build configuration

Use Cases

  • Laravel/Symfony workers — queue consumers, scheduled commands
  • Kafka/RabbitMQ consumers — event-driven microservices
  • Cron jobs — scheduled tasks in containers
  • Deployment scripts — migrations, seed data, cache warmup
  • CI/CD — test runner with PCOV for fast coverage