Skip to content

Debian packaging for phpr (phpr-cli, phpr-server) with a trixie build lane - #10

Closed
bzed wants to merge 7 commits into
francescotinti:mainfrom
bzed:debian-packaging
Closed

bzed wants to merge 7 commits into
francescotinti:mainfrom
bzed:debian-packaging

Conversation

@bzed

@bzed bzed commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

What this adds

A native Debian source package phpr (new php-rust/debian/) producing two binary packages, plus a CI lane that builds, gates and publishes them.

phpr-cli

  • /usr/bin/phpr, registered via update-alternatives as /usr/bin/php (priority 85 — the 8.5 slot), so tooling that invokes php keeps working.
  • Provides/Conflicts/Replaces: php8.5-cli; also Provides: php-json.
  • Known, documented gaps (in README.Debian): no php.ini is read, -v/-m/-i/-l/-w/--ini are not implemented, archive php8.5-* extension modules have no effect on phpr.

phpr-server

  • /usr/bin/php-server, a php -S work-alike web SAPI: sequential cli-server mode and --axum multi-worker mode (shared FIFO queue, one fresh VM per request).
  • Ships a systemd unit (phpr-server.service, runs as www-data; host/port/docroot/workers configured in /etc/default/phpr-server).
  • Not FastCGI: it does not speak the FPM protocol and does not replace php8.5-fpm behind nginx/Apache — front it with any reverse proxy over plain HTTP.

Packaging details: debhelper compat 13, Rules-Requires-Root: no, vendored-static onig (RUSTONIG_STATIC_LIBONIG=1) for reproducibility (system zlib stays a dynamic link for byte-parity), libclang-dev for bindgen, manpages, lintian overrides, and autopkgtest-style installed-package smoke tests in debian/tests/{cli,server}.

CI lane (debian-packages.yml)

Deliberately separate from the unit-test gate: it only reacts to the debian-packaging branch and publishes the artifacts.

  • Builds on debian:trixie (the suite the runtime depends target: libgd3, libtidy58).
  • trixie cannot satisfy the rustc (>= 1.98) Build-Depends, so the lane installs the Build-Depends explicitly minus rustc/cargo and installs the PINNED toolchain (rust-toolchain.toml, currently 1.98.1) via rustup fetched with curl from the official https://sh.rustup.rs installer — the compiler follows the pin, never the suite.
  • dpkg-buildpackage -us -uc -d: dpkg cannot see the external toolchain and trixie's rustc (1.85) could never satisfy ">= 1.98" anyway; every other depend was installed explicitly (the contract is documented in debian/control and debian/rules).
  • lintian --pedantic --fail-on error. The new debian/source/lintian-overrides overrides license-problem-php-license (trixie's lintian raises it as an error on the deliberate PHP-3.01 licensing, which sid's lintian did not emit), keeping the gate meaningful on every suite.
  • Installs both built .debs in the container and runs debian/tests/cli + debian/tests/server.
  • Publishes .deb, .dsc, .tar.xz, .changes, .buildinfo as workflow artifacts.

Validation

  • Branch CI green: the debian-packages lane completed successfully on this branch (run #6, ~8 min).
  • Replicated end-to-end in a rootless podman debian:trixie container: cold build with the rustup-installed pinned toolchain, strict lintian (0 E: tags), clean dpkg -i, both packaged smoke tests green.
  • The installed packages then ran WordPress 7.1.5 fully on the packaged php-server --axum against MySQL: install through the engine (12 tables, admin user), front page, pretty permalinks, RSS2 feed, login POST (302 to wp-admin), REST wp-json.
  • No Rust sources are touched; this branch is main + exactly the 7 packaging commits.

Apt repository CI flow — an offer

We would also be happy to provide a full apt repository CI flow on top of this lane: an apt-consumable repository (package pool, Packages/Sources/Contents indexes, signed Release/InRelease) published automatically from CI, so users can add one sources.list line and apt install phpr-cli.

We usually target GitHub Pages for this — zero hosting cost, the whole flow stays inside Actions, and the repository can be served from the same Pages site — but we are equally happy to support other deployments: self-hosted nginx, S3/static hosting, or an aptly-based setup. Whatever fits this project's infrastructure preferences. Happy to bring that as a follow-up PR if this packaging is of interest.

bzed added 7 commits November 22, 2026 20:15
Source package "phpr", format 3.0 (native), debhelper compat 13.
Two binary packages, own namespace with PHP provides:

- phpr-cli ships /usr/bin/phpr and registers it as the /usr/bin/php
  alternative at priority 85 (the 8.5 slot; php8.4-cli=84, php8.6-cli=86
  still outrank it and coexist). Provides: php-cli, php8.5-cli, php-json,
  php8.5-json; Conflicts/Replaces: php8.5-cli. The phpapi-* ABI is
  deliberately NOT provided: phpr loads no binary extensions.

- phpr-server ships /usr/bin/php-server (union build: cli-server +
  axum-server) and a hardened systemd service running as www-data,
  configured via the /etc/default/phpr-server conffile (host, port,
  docroot /var/www/html, workers). The service claims NO php-fpm
  (php-server speaks plain HTTP, not FastCGI): README.Debian documents
  the reverse-proxy pattern instead.

Correct-or-absent is preserved end-to-end: no /etc/php/8.5 tree (the
engine reads no php.ini), and the missing -v/-m/-i/-l/-w/--ini switches
are documented as gaps in the phpr-cli README.Debian and the man page.

Packaging hardening earned along the way:
- rules pins RUSTC=/usr/bin/rustc and strips ~/.cargo/bin from PATH so
  cargo never resolves the rustup shim (one poisoned-cache incident:
  shim mixed rustc 1.99.1/1.98.1/1.71.0 in a single build).
- RUSTONIG_STATIC_LIBONIG=1 pins the vendored static oniguruma so the
  binaries are identical regardless of the build host; zlib stays the
  SYSTEM library (byte-parity contract).
- source tarball kept lean via debian/source/options tar-ignore (the
  harness/sessions/gaps trees are dev history, not build inputs).
- shlibs.local maps libtidy.so.58 for hosts without libtidy58 in the
  dpkg database; runtime Depends are explicit (libgd3, libtidy58).
- autopkgtest smoke suites for both packages (debian/tests/).
- lintian --pedantic: clean, with two justified binary overrides
  (ureq/unsafe-libyaml Rust crates misdetected as embedded C libs;
  /var/www/html default docroot, established nginx/apache2 practice).

Built and verified on Debian forky/sid with Debian's rustc/cargo 1.98.1
(the project's pinned toolchain).
Runs only on the debian-packaging branch (and on demand): ci.yml's
main-branch gate is untouched. The job builds in a debian:sid container
— the same distro the packages target and the one the packaging was
verified on — with these properties:

- deps come from debian/control via "apt-get build-dep" (single source
  of truth; no duplicated toolchain list);
- a pin-guard step fails the build loudly if debian:sid's rustc drifts
  away from the toolchain pinned in rust-toolchain.toml (1.98.1): a
  compiler change must be deliberate, never smuggled in by a moving
  container tag;
- lintian runs with --fail-on error (warnings displayed, not fatal);
- the autopkgtest smoke scripts (debian/tests/{cli,server}) run against
  dpkg -i installed packages before upload;
- artifacts: phpr-cli/phpr-server debs + the native source set,
  .changes and .buildinfo.
The stock debian:sid container ships no rustc/cargo; they arrive via
apt-get build-dep (from debian/control). The environment report step
ran before that and failed with exit 127 (rustc: not found).
The minimal debian:sid image ships no CA store: cargo's TLS to the
crates.io registry failed (unable to update registry crates-io), and
curl would have hit the same wall in the smoke test.
Toolchain policy: Debian's rustc/cargo when they match the pin in
rust-toolchain.toml (unchanged, deterministic default), and the PINNED
toolchain via rustup when they do not. debian/rules now accepts a
caller-supplied CARGO/RUSTC pair via the environment (both must name
the same toolchain; the PATH restriction keeps rustup's proxy shims
out of the build either way). The CI resolve step picks the mode and
hands the absolute paths to dpkg-buildpackage.

Verified locally: make honors the env pair; in a debian:sid container
apt's rustup installs the pinned 1.98.1 toolchain and rustup-which
resolves real non-shim paths.

Also: libclang-dev added to Build-Depends — onig_sys's vendored
oniguruma build runs bindgen, which probes libclang at build time
(present on dev boxes, absent in minimal containers; the CI run died
on it).
update-alternatives --query prints 'Alternative: /usr/bin/phpr' — the
bare-path line the old grep expected does not exist in its output, so
the registration check could never pass (the CI smoke run caught it;
the podman install verification had checked the equivalent facts with
inline commands and never executed this script verbatim).

Both debian/tests scripts now verified end-to-end in a debian:sid
container against dpkg-installed packages.
…ed rustup toolchain

- debian-packages.yml: build container debian:sid -> debian:trixie.
  trixie's rustc (1.85) can never satisfy the "rustc (>= 1.98)"
  Build-Depends, so the lane installs the build dependencies explicitly
  MINUS rustc/cargo and always installs the PINNED toolchain with
  rustup fetched with curl from the official https://sh.rustup.rs
  installer. dpkg-buildpackage runs with -d: dpkg cannot see the
  external toolchain, and every other depend was installed explicitly.
- debian/source/lintian-overrides: override license-problem-php-license
  (raised as an ERROR by trixie's lintian on the deliberate PHP-3.01
  choice; sid's lintian did not emit it), keeping the --fail-on error
  gate honest on every suite.
- control/rules comments document the trixie toolchain contract.

Validated end-to-end in a rootless podman debian:trixie container:
build with the pinned rustc/cargo 1.98.1, lintian gate, dpkg -i, both
autopkgtest-style smokes green; the packages then ran WordPress 7.1.5
on php-server --axum with all functional checks passing.
@francescotinti

Copy link
Copy Markdown
Owner

Thank you very much, Bernd — this is a remarkably careful piece of work, and it is a real pleasure to receive it from a Debian developer.

I read the whole series. What I particularly appreciated:

  • the honesty of the packaging: no phpapi-* claim, no /etc/php/8.5 tree, no php-fpm pretence, and the missing CLI switches documented in README.Debian and in the man page — exactly the project's correct-or-absent rule, applied to a package;
  • the toolchain discipline: the compiler follows the pin in rust-toolchain.toml and never the suite, with the rustup shims kept out of the build;
  • vendored static oniguruma for reproducibility while zlib stays the system library, which is what our byte-parity contract needs;
  • the hardened systemd unit, the lintian overrides each with its justification, and the installed-package smoke tests.

Status on this side:

  • main had moved since your branch point, so I replayed your seven commits on top of the current main, unchanged and with your authorship preserved (e51fb9a2 … ff55d3d2, content identical to this PR). They are on the upstream branch debian-packaging, so your lane triggers here as designed.
  • Your lane is green upstream on that commit: debian-packages run — build on trixie with the pinned toolchain, lintian gate, dpkg -i, both smoke tests, artifacts published.
  • The project's own per-commit CI (build and full test battery) is green on the same commit; no Rust source is touched, as you said.
  • The fast-forward of main to that commit is the last step and follows shortly; I will close this PR with the final SHAs once it is done (GitHub does not mark replayed commits as merged).

About the apt repository flow: the offer is very welcome and much appreciated. I will come back to you on the hosting choice before you invest time in a follow-up PR.

Thanks again for the time and the care you put into this.

(Written with the help of an AI assistant, Claude, on behalf of the maintainer.)

francescotinti pushed a commit that referenced this pull request Nov 28, 2026
…and validated, state recorded in NEXT_SESSION: the fast-forward of main is left to the user

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@bzed

bzed commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi!

You are welcome!
Regarding the repositories: what I usually do (at least until there is a better place):

  • have a gpg key in the github secrets,
  • build and sign packages in the CI
  • publish them on github pages.

https://bzed.github.io/dayz-server-operator/installation.html has a rendered documentation example and https://github.com/bzed/dayz-server-operator/blob/main/.github/workflows/ci.yml the code.

Guess if you point claude to it you can get something similar.

What the debian package is still missing is a way to setup multiple phpr servers, guess using systemd templates would be an option. But I decided that should be your decision and that should be a general way on how to handle these things that is similar over all distributions. For now a single server for testing should be enough I guess.

Cheers,

Bernd

francescotinti pushed a commit that referenced this pull request Nov 29, 2026
… published on GitHub Pages

Follows the flow Bernd Zeimetz described on PR #10 (and uses in
dayz-server-operator): a GPG key in the repository secrets, packages
built and signed in CI, the repository published on GitHub Pages.

- packaging/apt/build-apt-repo.sh: reprepro repository (suite stable,
  codename trixie, amd64) from the .deb files, signed with the only key
  in GNUPGHOME; only packages named in debian/control are accepted.
- packaging/apt/snapshot-version.sh: <changelog version>+git<commit
  time, UTC>.<sha>, so every later build is an upgrade for apt.
- debian-packages.yml: the lane also runs on main; new jobs build the
  repository, install both packages from it with apt in a clean trixie
  (Signed-By enforced), and on main publish it on Pages and install
  again from there. Off main, or until the archive key is set up, the
  repository is signed with a throwaway key and never leaves the run.
  The archive key signs only the head of main, and only when the secret
  matches the committed public key. New actions pinned by commit SHA.
- packaging/apt/README.md: installation and the one-time maintainer
  setup (key, secret, Pages).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@francescotinti

Copy link
Copy Markdown
Owner

Thank you, Bernd — the pointer to your dayz-server-operator setup was exactly what was needed, and I followed it closely.

What is now on the upstream branch debian-packaging (commit e5cdc771, on top of your seven):

  • php-rust/packaging/apt/build-apt-repo.sh: a reprepro repository (suite stable, codename trixie, amd64) built from the lane's .deb files and signed with the only key in a temporary GNUPGHOME; only packages named in debian/control are accepted.
  • Snapshot versions in the spirit of your debian-snapshot.sh: 0.1.0+git<commit time, UTC>.<sha>, so each later build is an upgrade for apt and still sorts before the next changelog version (commit time rather than commit count, since there are no release tags yet and a shallow clone is enough).
  • Your lane gained four jobs after the build: build the repository, install both packages from it with apt in a clean trixie container with Signed-By enforced, publish on GitHub Pages, and install once more from the published URL. I kept your two safeguards: the archive key signs only the commit that is the head of main, and the deploy asks again at the last moment.
  • Off main, or as long as the archive key is not set up, the repository is signed with a throwaway key made in the run and never leaves it, so the whole path is exercised on every run without a secret being involved.

That rehearsal path is green: lane run — packages 0.1.0+git20261129055810.e5cdc77, repository built and signed, apt install phpr-cli phpr-server from it, interpreter runs.

What is not done yet, to be plain about it: nothing is published. The publishing jobs have never run; they need the archive key in the secrets, its public half committed, Pages switched to "GitHub Actions", and the fast-forward of main — all four are the maintainer's own steps and are written down in php-rust/packaging/apt/README.md. I will report here when the first signed repository is live.

On several phpr-server instances: I agree with your reading. A systemd template (phpr-server@.service with one /etc/phpr-server/<name>.conf each) looks like the natural shape, but it should be decided once for all distributions, so the package stays at a single instance for now and the question is noted as open on our side.

Thanks again for taking the time to explain your approach.

(Written with the help of an AI assistant, Claude, on behalf of the maintainer.)

francescotinti pushed a commit that referenced this pull request Nov 29, 2026
…r implemented on debian-packaging (e5cdc77, rehearsal green); state recorded in NEXT_SESSION and in the session minutes

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@francescotinti

Copy link
Copy Markdown
Owner

Landed. main was fast-forwarded to e5cdc771:

  • your seven commits, replayed unchanged with your authorship: e51fb9a2 … ff55d3d2;
  • the apt repository flow on top: e5cdc771.

GitHub does not mark replayed commits as merged, so I am closing the PR by hand — it is merged in substance. The lane now also runs on main; until the archive key and Pages are set up it stays a rehearsal and publishes nothing. I will leave a note here when the first signed repository is live.

Thank you again, Bernd.

(Written with the help of an AI assistant, Claude, on behalf of the maintainer.)

francescotinti pushed a commit that referenced this pull request Nov 29, 2026
…186-firma

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
francescotinti pushed a commit that referenced this pull request Nov 29, 2026
…k branch; what is left is the archive key and Pages

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@francescotinti

Copy link
Copy Markdown
Owner

A correction to what I wrote above, after a decision of the maintainer: the repository will not follow main.

  • Only a release tag publishes (v<version of debian/changelog>, on a commit that is on main). A push to a branch is always a rehearsal with a throwaway key.
  • Every released version stays installable. Since Pages replaces the whole site at each deploy, the GitHub releases are the durable store: the lane attaches the packages to the release and rebuilds the repository from all releases at every publish; a re-run of a tag reuses the released packages, so a published version never changes its bytes.
  • One thing that may be useful to know: the reprepro in trixie keeps a single version per package (no Limit field yet), so the index is now made with apt-ftparchive and signed with gpg directly.

On debian-packaging as 170dbfbf and 68f81cd6; the rehearsal, which now also checks that two versions are offered side by side and that apt can go back to the older one, is green: lane run. Still nothing published, and main does not have these two commits yet.

(Written with the help of an AI assistant, Claude, on behalf of the maintainer.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants