ModernPHP is a native PHP build system written in Go.
Build standalone PHP applications with FrankenPHP, parallel dependency compilation, and granular content-addressable artifact caching.
The default build targets Linux amd64 with glibc and requires Docker with Buildx and internet access for the first build. Build the ModernPHP CLI with Go 1.25 or newer. On an Apple Silicon Mac, you can also build and run the PHP application natively.
Use a release bundle to install a prebuilt CLI. The Linux amd64 archive also contains a runnable example app. The Apple Silicon archive contains the macOS CLI.
git clone https://github.com/andreybolonin/modernphp.git
cd modernphp
CGO_ENABLED=0 go build -o modernphp ./cmd/modernphp
./modernphp doctor
./modernphp buildOn Linux amd64, run the embedded example from the repository root.
./dist/app/current/app php-cli public/index.php
./dist/app/current/app php-server --listen 127.0.0.1:8080The CLI prints modernphp-php. With the server running, open http://127.0.0.1:8080/ or run curl http://127.0.0.1:8080/ in a second terminal. The first build fetches and compiles pinned dependencies. Try ./modernphp build again to reuse the local artifact cache.
Put modernphp.yaml next to your application directory. In this example, app/public/index.php is the HTTP entry point. Include any Composer dependencies you need in app/vendor/ before building.
schema: 1
php:
version: '8.5.13'
zts: true
target:
type: frankenphp
os: linux
arch: amd64
libc: glibc
extensions: [pdo_mysql, mbstring, openssl]
application:
path: app
embed: true
build:
backend: native
cache: true
output:
path: dist/appIf you are working outside the cloned repository, put the modernphp CLI on your PATH or invoke it by absolute path.
modernphp validate
modernphp plan
modernphp lock
modernphp build --lockedEach command accepts --config path/to/modernphp.yaml. Paths in YAML are relative to that config file. Set application.embed: false to build a FrankenPHP runtime that reads your app from disk. Serve it with app php-server --root /path/to/app/public --listen 127.0.0.1:8080, using the generated binary at dist/app/current/app. Use application.exclude with Go filepath.Match patterns to omit files from the embedded app. Keep credentials outside the application directory.
For a public domain, the built-in server supports automatic HTTPS through php-server --domain example.com. It obtains certificates as an ACME client. Caddy’s acme_server handler issues certificates to other clients and is outside the 1.0 support scope. Leave it disabled in custom Caddy configurations.
On an Apple Silicon Mac, select the macOS target in modernphp.yaml.
php:
version: '8.5.13'
zts: true
target:
type: frankenphp
os: darwin
arch: arm64
libc: libsystem
extensions: [filter, session, tokenizer]Keep the application and output settings from your own configuration. This target builds with Go 1.27.3 or newer, Clang from the Xcode Command Line Tools, pkg-config with libxml-2.0, and a local PHP ZTS installation of the configured version with the embed SAPI and headers. See the FrankenPHP build guide for preparing PHP on macOS.
export MODERNPHP_PHP_CONFIG=/path/to/php-zts/bin/php-config
modernphp doctor
modernphp build
./dist/app/current/app php-server --listen 127.0.0.1:8080If the matching php-config is already on your PATH, omit the export. The extensions field checks the modules provided by your local PHP. The resulting executable runs directly on macOS and uses your installed libphp when linked dynamically. The macOS target uses host dependencies and the Go build cache. Lockfiles, offline builds and the native dependency SBOM apply to the Linux target.
Set an exact version in your YAML config for a native FrankenPHP build.
php:
version: '8.6.0'
zts: true
extensions: [bcmath, ctype, filter, opcache, session, tokenizer]- 8.5.13 is the default and supports the full extension catalog below. The existing
8.5alias resolves to this exact version. - 8.6.0 is supported with a limited extension catalog. Select from
bcmath,ctype,filter,opcache,session, andtokenizer. Omitextensionsto select this profile, or specify a subset. CI compiles the locked profile offline and checks the downloaded bundle on a separate Linux amd64 runner.
An unsupported version or extension combination fails during planning. Refresh the lockfile after switching versions. The upstream reference backend uses 8.5.13.
Set extensions in your YAML config to choose the native build profile.
extensions: [pdo_pgsql, redis, bcmath, zip]On PHP 8.5.13, omit the field for the default 14-extension profile or set extensions: [] for the core PHP build. ModernPHP enables required dependencies such as PDO for pdo_pgsql and libxml for dom and xml. PHP core modules, including OPcache in PHP 8.5, may still be present. The manifest lists the requested and loaded extensions.
The catalog accepts amqp, apcu, bcmath, calendar, ctype, curl, deepclone, dom, exif, fileinfo, filter, ftp, gd, grpc, iconv, imagick, intl, mbstring, memcached, mongodb, mysqli, opcache, openssl, pcntl, pdo, pdo_mysql, pdo_pgsql, pdo_sqlite, posix, protobuf, redis, session, shmop, simplexml, soap, sockets, sodium, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter, yaml, and zip. Unknown names fail during planning. Refresh the lockfile after changing the list.
Select session alongside redis or memcached to enable the corresponding PHP session handler. The Memcached profile uses bundled FastLZ and zlib compression. The MongoDB profile uses OpenSSL TLS and zlib compression. MongoDB client-side field-level encryption and Memcached SASL are outside these profiles.
Select sqlite3, pdo_sqlite, or both. pdo_sqlite enables PDO, and xmlreader enables DOM. SQLite is built with runtime loading of external SQLite extensions disabled.
For MySQL, select mysqli, pdo_mysql, or both. These use mysqlnd with TLS support. gd and imagick support PNG and JPEG. See CI runs for Linux amd64 validation of the full catalog.
./modernphp lock
./modernphp build --lockedThe lock command writes modernphp.lock next to the selected configuration. It records the resolved native recipe graph, source and module checksums, PHP and extension profile, and compiler and verification image digests. The current registry already supplies exact pins, so creating the lockfile needs neither Docker nor a registry lookup. Commit the lockfile with the configuration.
A locked build rejects drift before compilation and leaves the lockfile intact. Edit application files and change the output path or cache setting without refreshing the lock. Run modernphp lock explicitly when changing the build profile or upgrading the recipe registry. Locked builds can fetch missing pinned inputs online.
./modernphp build --offline --lockedWith caching enabled, run a locked build online first. Offline mode restores the verified final artifact for the same staged app and runs its verification using the pinned Debian image already present in local Docker. It skips source fetches, dependency builds, linking, and image pulls. An absent or corrupt entry leaves the previously published bundle in place.
./modernphp lock
./modernphp prepare --locked
./modernphp build --offline --locked --compileRun prepare with network access. It fetches the pinned compiler and Debian images into local Docker, caches verified source archives, and prepares a local Go module proxy from the pinned FrankenPHP module files. Source patches and recipe commands are embedded in ModernPHP and covered by the lock. Keep the same Docker daemon and MODERNPHP_CACHE_DIR for the offline build.
The offline compilation command checks the complete input set before starting a compiler. It runs each recipe and FrankenPHP linking with Docker networking disabled and image pulling blocked. It can reuse cached outputs. Set build.cache: false to bypass the compiled-result cache. If a lockfile was produced by an older recipe registry, refresh it with modernphp lock before preparing inputs.
The default bundle is dist/app/current. It contains app, manifest.json and licenses/. Tools reading several members should resolve current once and use that generation for all reads. On build failure the previous published generation stays available. Old generations are retained.
Native Linux builds also publish sbom.cdx.json in CycloneDX 1.6 format. The SBOM records the executable SHA-256, native recipe sources and licenses, loaded PHP modules, and Go modules from the executable's build metadata. Its inventory covers ModernPHP's native recipes and runtime probe. The system libraries listed in the manifest, toolchain-supplied native libraries, and embedded application dependencies need separate inventory and scanning.
On release tags and manual runs, Linux amd64 CI scans the full PHP 8.5.13 catalog with Grype and uploads grype.json alongside the exact SBOM and build manifest. Go matches use package URLs. Grype can infer missing CPE identifiers for native libraries, so review those matches and check coverage before a release. Findings are reported for triage. Scanner errors fail the CI step. To scan another native bundle with the same matching options, run grype sbom:dist/app/current/sbom.cdx.json --add-cpes-if-none -o json.
The manifest lists linked libraries for ELF on Linux and Mach-O on macOS. Verify the executable in its intended runtime environment before distribution. The upstream ADR describes online inputs and license coverage.
A release tag such as v1.0.0-rc.1 runs the Linux amd64 release workflow. The build prepares pinned inputs, compiles the PHP 8.5.13 profile offline, and runs CLI and HTTP smoke tests. A separate job signs the archive digest in a Sigstore SLSA provenance bundle, verifies the attestation against the tag and commit, and creates a GitHub release draft for review.
Download modernphp-linux-amd64.tar.gz, SHA256SUMS, and provenance.sigstore.json from the same release. Set tag to the release tag you downloaded, then verify the archive before extraction.
tag=v1.0.0-rc.1
repo=andreybolonin/modernphp
sha256sum --ignore-missing --check SHA256SUMS
gh attestation verify modernphp-linux-amd64.tar.gz \
--bundle provenance.sigstore.json --repo "$repo" \
--signer-workflow "$repo/.github/workflows/release.yml" \
--source-ref "refs/tags/$tag"
tar -xzf modernphp-linux-amd64.tar.gz
cd modernphp-linux-amd64
sha256sum --check SHA256SUMS
./modernphp --helpThe archive includes the ModernPHP CLI, its license, and the locked example configuration and source. The example/ directory contains the verified FrankenPHP executable, its manifest, SBOM, and license files.
The Accept ModernPHP release workflow takes a release tag, verifies the downloaded archive, and scans its exact example/sbom.cdx.json with Grype. The resulting CI artifact contains the report, SBOM, build manifest, and release archive checksum.
On an Apple Silicon Mac, download modernphp-darwin-arm64.tar.gz, SHA256SUMS, and provenance.sigstore.json from the same GitHub release. Set tag to that release tag before running the verification commands.
repo=andreybolonin/modernphp
archive=modernphp-darwin-arm64.tar.gz
grep " $archive$" SHA256SUMS | shasum -a 256 --check
gh attestation verify "$archive" \
--bundle provenance.sigstore.json --repo "$repo" \
--signer-workflow "$repo/.github/workflows/release.yml" \
--source-ref "refs/tags/$tag"
tar -xzf "$archive"
./modernphp-darwin-arm64/modernphp --helpThe CLI runs natively on macOS. Select darwin/arm64 to build an app for your Mac, or use the default Linux target with Docker and Linux amd64 support.
go test -race ./...
go vet ./...Run the native compiler and acceptance checks on a Linux amd64 runner with Docker Buildx.
CGO_ENABLED=0 go build -o modernphp ./cmd/modernphp
tests/integration/native-amd64.sh ./modernphpBranch pushes and pull requests build and smoke-test the full PHP 8.5 extension catalog once. Use tests/integration/native-amd64.sh ./modernphp 8.5.13 catalog to run the same check locally. Tags and manual runs of ModernPHP Linux amd64 also check the default profile, cache reuse, clean offline builds and reproducibility, then scan the full catalog with Grype. Complete the tag run before publishing the release draft. The smoke script needs Python 3.11 or newer. To run the recipe-level integration tests, use MODERNPHP_NATIVE_INTEGRATION=1 go test -v -timeout 70m ./internal/native.
The branch and PR workflow restores native source archives, compiled libraries, and libphp from the GitHub Actions cache. ModernPHP verifies the archive SHA-256 and checks each compiled entry against its recipe key and artifact digest. The final FrankenPHP executable is linked in each run, so app changes use the same dependency cache. The full acceptance workflow starts with a fresh ModernPHP cache.
See the RFC for milestones, the native recipe ADR for the build architecture, and the reproducibility ADR for how CI compares clean builds.
ModernPHP is licensed under the MIT License. Bundled third-party components retain their own licenses.