Related posts
- Dropping the packages: compiled nginx, PHP and Valkey, and what the migration tests broke
My setup script now builds nginx, PHP and Valkey from source and installs none of them from packages. Live servers migrate once, on --optimize. Testing that migration and a PHP downgrade chain found eight bugs, including a build log that grew to 1.7 TB. A day later, 1.22.1 dropped pre-compressed static files.
- Whitespace is cheap: the nginx trim filter lost, and five setup options became automatic
I built Tengine's HTML trim filter into my compiled nginx and measured it on a seeded XenForo forum. It made member pages 7-10 % smaller and every PHP-rendered page 1.6-3 % slower, so it did not ship. The same release of my setup script turns five command-line options into values derived from the hardware, shows what --optimize is compiling and why, closes a root chown race in a nightly cron job, and tightens the XenForo guest cache.
- Setup script 1.22.5, before and after: XenForo 17-32 % faster on the same box
I benchmarked the whole 1.22.5 release against 1.22.4 the way a server gets it: an --optimize run, a reboot, then load. Cached XenForo pages went from 122k to 161k req/s, uncached pages 17-22 % faster, p99 14-20 % lower, and PHP-FPM uses half the memory. Most of it is the kernel; the rest is a new allocator for PHP, a lower Brotli level and AWS-LC under nginx. The benchmark also caught a bug that would have stopped every updated server from rebuilding PHP.
My setup script compiles nginx, PHP and Valkey from source on Ubuntu and tunes them to the hardware. Three small releases went out this week (1.22.42 to 1.22.44). Each one came from something I watched happen on a real server.
The builds now start from an up-to-date system#
Before running
--optimize, I used to type the same line by hand on every server:Now the script runs it itself, as the first step of a new install and of every
--optimize, before any source build. A compiler, linker or library from Ubuntu’s own updates is then in place before nginx or PHP is built against it. One function covers both cases, and they differ only in what happens around the upgrade.Nothing gets restarted behind your back. On Ubuntu 24.04 and later, a plain
apt upgradelets needrestart restart every service that uses an upgraded library. On a live web server that means nginx, PHP-FPM, Valkey and MariaDB, one after another, in whatever order it picks. The script suspends needrestart for the upgrade. The report then lists the services still on an old library and says Reboot needed when the kernel or core libraries changed. You choose when to restart, with--restart-allor a reboot. A fresh install is different: nothing is serving yet, so it restarts what needs it right away, as before.A broken upgrade doesn’t take the run down. If dpkg fails mid-upgrade, the step repairs it once (
dpkg --configure -a, thenapt-get -f install --no-remove) and tries again. If it still fails,--optimizemarks the step FAILED in its report, carries on tuning everything else and exits non-zero. A local change to a package’s config file is always kept (--force-confold), so the run never stops at a conffile prompt.--optimize --dry-runshows how many packages are due, andSETUP_OPTIMIZE_APT=0skips the upgrade for one run.The install that failed on a mirror#
I tested that release with a fresh install on my test server, and it failed halfway. The hosting provider’s Ubuntu mirror was answering 503 for
automakeandlibtool, two packages the PHP build needs. My script was fine; the provider’s copy of Ubuntu was down. On a server you’re setting up at 2 a.m., that’s the whole evening gone.My first thought was to mirror Ubuntu’s packages myself. That’s the wrong fix: a copy of the archive is a lot of storage to keep in sync, and it would be one more mirror that can go down. apt already has the right tool, the
mirror+file:method. A sources entry points at a list of mirrors in priority order, and apt moves to the next mirror for each file that fails.So the package step now begins by rewriting the Ubuntu entries in
ubuntu.sources(or the oldersources.list) to use two such lists:The security list works the same way and starts with the server’s own security mirror. The mirror the server already used stays first, so on a normal day nothing changes and the fast local mirror does the work. On a bad day, apt falls back to Canonical’s main archive, then to kernel.org’s copy.
This is safe because the trust is in the signatures, not the mirror. Every index is signed by Ubuntu’s archive key, and apt checks it whichever mirror served the file. A few more guard rails:
apt-cache policyand puts the original files back if apt rejects it.--purge basicrestores the original files byte for byte. It also removes the two lists.ports.ubuntu.com, which has its own mirrors.The proof was a rerun of the failed test: the same server, with its own mirror still answering 503. The install finished, and the apt log showed
automakeandlibtooldownloaded from the fallback.Checking every live server before deleting code#
The script carried code to cope with older releases: it accepted CPU fingerprints recorded by 1.22.0-1.22.4 builds, and it could restore
/etc/security/limits.confunder a narrow condition. I wanted it gone, but deleting it blind is how a live server gets a surprise rebuild. So first I ran a read-only check across all 21 live servers:build.infofiles (nginx, PHP, Valkey) record the current fingerprint and match their CPU exactly, so nothing needs the old acceptance.Both pieces were removed. That cleared the way for a wider sweep. One reviewer listed what looked unused, and a second one tried to prove each item was still needed. About 11,000 lines left the two repositories: dead variables, roughly 45 checks that could never fail, nginx templates the script never renders, old audit reports and finished benchmark tools. Nothing rebuilds and nothing behaves differently; git history keeps all of it.
A 20-second walk through attachments#
Every
--optimizechecks each site for SQLite use, so the PHP build keeps the SQLite modules only where something needs them. On a big XenForo forum the check ran out of its 20-second budget on every run. It was walkingdata/andinternal_data/, where XenForo keeps every attachment, avatar and thumbnail. Those trees hold no code and no database, so a XenForo root (andwp-content/uploadsfor WordPress) now skips them. On a test site with 603,001 files, the scan dropped from 2-2.8 seconds to 0.3, and it no longer grows with the attachments.1.22.42 then went to all 21 live servers with
--optimize. Every run succeeded, no service restarted, every page probe passed, and XenForo’s error logs stayed empty.The test server went back to its recorded clean state afterwards: the same 701 packages, now with twelve newer versions from Ubuntu’s updates, which is the new step doing its job.