<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Ubuntu Tips</title><link>https://ubuntips.com/</link><description>Practical notes on provisioning, tuning and hardening Ubuntu servers.</description><language>en-US</language><generator>Hugo</generator><lastBuildDate>Sat, 21 Nov 2026 14:45:00 +0800</lastBuildDate><atom:link href="https://ubuntips.com/index.xml" rel="self" type="application/rss+xml"/><item><title>XenForo on Valkey: do you need php-redis?</title><link>https://ubuntips.com/posts/xenforo-valkey-php-redis-vs-sv-rediscache/</link><guid isPermaLink="true">https://ubuntips.com/posts/xenforo-valkey-php-redis-vs-sv-rediscache/</guid><pubDate>Sat, 21 Nov 2026 14:45:00 +0800</pubDate><dc:creator>Draft</dc:creator><description>Six XenForo cache setups, 300 load-test runs, MariaDB local and simulated remote. The PHP extension barely matters; the cache itself does.</description><category>Xenforo</category><category>Valkey</category><category>Redis</category><category>Php</category><category>Mariadb</category><category>Benchmark</category><content:encoded><![CDATA[<p>XenForo can store its cache in Redis or Valkey in two ways. The core provider needs the <code>php-redis</code> extension. The popular SV RedisCache add-on ships its own pure-PHP client (Credis) and works with no extension at all. I wanted to know whether <code>php-redis</code> is worth making a hard requirement for every XenForo server, so I measured it.</p>
<p>Short answer: no. On the forum, thread and mixed pages the two clients are within about 2% of each other, with the database on the same box or on a simulated remote server. The only larger gaps came from single noisy rounds, and they favoured the pure-PHP client. What matters is that the cache is on, and that the SV add-ons are installed.</p>
<h2 id="the-six-setups" class="heading-anchor">The six setups<a class="anchor" href="#the-six-setups" aria-label="Link to section: The six setups">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Setup</th>
					<th>PHP extensions</th>
					<th>Cache provider</th>
					<th>Serializer</th>
					<th>SV add-ons</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><strong>A</strong></td>
					<td>redis + igbinary</td>
					<td>SV RedisCache, using phpredis</td>
					<td>igbinary</td>
					<td>RedisCache, RedisFloodCheck, RedisViewCounter</td>
			</tr>
			<tr>
					<td><strong>A+</strong></td>
					<td>redis + igbinary</td>
					<td>same as A, persistent connections</td>
					<td>igbinary</td>
					<td>all three</td>
			</tr>
			<tr>
					<td><strong>B</strong></td>
					<td>igbinary only</td>
					<td>SV RedisCache, pure-PHP Credis</td>
					<td>igbinary</td>
					<td>all three</td>
			</tr>
			<tr>
					<td><strong>C</strong></td>
					<td>none</td>
					<td>SV RedisCache, pure-PHP Credis</td>
					<td>PHP <code>serialize</code></td>
					<td>all three</td>
			</tr>
			<tr>
					<td><strong>D</strong></td>
					<td>redis + igbinary</td>
					<td>XenForo core <code>'provider' =&gt; 'Redis'</code></td>
					<td>igbinary</td>
					<td>disabled</td>
			</tr>
			<tr>
					<td><strong>E</strong></td>
					<td>none</td>
					<td>cache off</td>
					<td>n/a</td>
					<td>installed, no backend</td>
			</tr>
	</tbody>
</table>
<p>C is the &ldquo;no extensions&rdquo; setup that many forums already run. Every other result below is compared against it.</p>
<h2 id="test-bed" class="heading-anchor">Test bed<a class="anchor" href="#test-bed" aria-label="Link to section: Test bed">#</a></h2>
<ul>
<li>One dedicated server: 6-core / 12-thread Xeon, 62 GB RAM, Ubuntu 26.04.</li>
<li>Angie, PHP-FPM 8.5 (<code>pm = static</code>, 12 children), MariaDB, and Valkey on a Unix socket. Everything was installed and tuned by the same <a href="/posts/one-idempotent-script/">provisioning script used for these notes</a>.</li>
<li>XenForo 2.3.13 filled with generated content. SV StandardLib, RedisCache 2.18.12, RedisFloodCheck and RedisViewCounter were installed.</li>
<li>64 logged-in members, picked at random on every request, reading 300 threads and 47 forums. Read state was pre-warmed so it did not grow during the runs.</li>
<li><a href="https://github.com/wg/wrk">wrk</a> at 24 connections for 20 seconds, for four page types: home, thread, forum list, and a mixed set. Two single-connection runs (<code>thread-c1</code>, <code>home-c1</code>) measured plain page latency.</li>
<li>Setups were run in rotated order across rounds: 3 rounds for the local and 0.9 ms databases, 2 for the others. All figures are medians.</li>
</ul>
<p>I only measured logged-in traffic. That is the traffic that always reaches PHP and the cache, while guest pages can be served from the web server&rsquo;s page cache.</p>
<h3 id="keeping-each-setup-honest" class="heading-anchor">Keeping each setup honest<a class="anchor" href="#keeping-each-setup-honest" aria-label="Link to section: Keeping each setup honest">#</a></h3>
<p>Cache benchmarks are easy to fool, so the harness did this before every setup:</p>
<ol>
<li>Write a neutral config, toggle the add-ons, then install or remove the PHP packages.</li>
<li>Write the setup&rsquo;s config, restart PHP-FPM, flush the cache database and drain XenForo&rsquo;s job queue.</li>
<li>Log all 64 members back in.</li>
<li>Check that the expected FPM modules are loaded, that most keys in a sample of up to 150 use the expected serializer, and that the SV add-ons are in the expected state. A setup that failed any check was skipped. None did.</li>
</ol>
<p>The XenForo cron job was disabled while measuring, so background jobs could not land in one setup&rsquo;s numbers. All 300 timed runs completed with zero errors. In a separate functional pass, each setup also posted a forum reply (HTTP 200) with no XenForo error-log entries and no PHP log lines.</p>
<h3 id="simulating-a-remote-mariadb" class="heading-anchor">Simulating a remote MariaDB<a class="anchor" href="#simulating-a-remote-mariadb" aria-label="Link to section: Simulating a remote MariaDB">#</a></h3>
<p>Some large forums run MariaDB on a separate server. To approximate that on one box, XenForo connected over TCP to <code>127.0.0.1</code>, and <code>tc netem</code> delayed only MariaDB traffic on the loopback interface:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">tc qdisc add dev lo root handle 1: prio bands <span class="m">4</span> priomap <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span> <span class="m">3</span>
</span></span><span class="line"><span class="cl">tc qdisc add dev lo parent 1:1 handle 10: netem delay 1000us
</span></span><span class="line"><span class="cl">tc filter add dev lo parent 1: protocol ip prio <span class="m">1</span> u32 match ip dport <span class="m">3306</span> 0xffff flowid 1:1
</span></span><span class="line"><span class="cl">tc filter add dev lo parent 1: protocol ip prio <span class="m">1</span> u32 match ip sport <span class="m">3306</span> 0xffff flowid 1:1
</span></span></code></pre></div><p>The priomap sends all other loopback traffic to the fourth band, which has no delay, so only port-3306 traffic goes through netem. Remove it afterwards with <code>tc qdisc del dev lo root</code>.</p>
<p>Both directions are delayed, so a 250 µs setting gave a measured <code>SELECT 1</code> median of <strong>0.9 ms</strong>, and 1,000 µs gave <strong>2.2 ms</strong>. Before each latency block, the harness measured the round trip (median of 500 <code>SELECT 1</code> queries) and aborted if it fell outside the expected range. A TCP run with no delay served as a control: TCP alone cost about 2% against the Unix socket. Persistent database connections (<code>p:</code> host prefix) were on in every run.</p>
<p>This simulates network latency only. A real remote server also has its own CPU, disk and network jitter.</p>
<h2 id="results" class="heading-anchor">Results<a class="anchor" href="#results" aria-label="Link to section: Results">#</a></h2>
<p>Throughput relative to C, for the forum, thread and mixed pages:</p>
<table>
	<thead>
			<tr>
					<th>Setup</th>
					<th>Local socket</th>
					<th>Remote, 0.9 ms</th>
					<th>Remote, 2.2 ms</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>A (php-redis + igbinary)</td>
					<td>+1.2 to +1.4%</td>
					<td>−0.1 to +1.0%</td>
					<td>+0.1 to +0.7%</td>
			</tr>
			<tr>
					<td>A+ (persistent)</td>
					<td>+1.5 to +1.9%</td>
					<td>+1.1 to +1.4%</td>
					<td>not run</td>
			</tr>
			<tr>
					<td>B (igbinary only)</td>
					<td>+1.0 to +1.6%</td>
					<td>+0.7 to +1.1%</td>
					<td>not run</td>
			</tr>
			<tr>
					<td>D (core provider, no SV)</td>
					<td>+2.6 to +3.4%</td>
					<td>−0.8 to +0.1%</td>
					<td>−4.8 to −6.2%</td>
			</tr>
			<tr>
					<td>E (no cache)</td>
					<td>+2.8 to +4.4%</td>
					<td>−4.3 to −5.6%</td>
					<td>−14.8 to −19.9%</td>
			</tr>
	</tbody>
</table>
<p>Raw throughput for the mixed page set, in requests per second:</p>
<table>
	<thead>
			<tr>
					<th>Setup</th>
					<th>Local socket</th>
					<th>Remote, 0.9 ms</th>
					<th>Remote, 2.2 ms</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>A</td>
					<td>332</td>
					<td>272</td>
					<td>173</td>
			</tr>
			<tr>
					<td>C</td>
					<td>329</td>
					<td>273</td>
					<td>171</td>
			</tr>
			<tr>
					<td>D</td>
					<td>337</td>
					<td>272</td>
					<td>161</td>
			</tr>
			<tr>
					<td>E</td>
					<td>338</td>
					<td>260</td>
					<td>143</td>
			</tr>
	</tbody>
</table>
<p>What a remote database does to a thread page with setup C:</p>
<table>
	<thead>
			<tr>
					<th>MariaDB round trip</th>
					<th>Thread req/s</th>
					<th>One request at a time (p50)</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>0.03 ms (Unix socket)</td>
					<td>350</td>
					<td>19.2 ms</td>
			</tr>
			<tr>
					<td>0.9 ms</td>
					<td>299</td>
					<td>35.0 ms</td>
			</tr>
			<tr>
					<td>2.2 ms</td>
					<td>188</td>
					<td>64.6 ms</td>
			</tr>
	</tbody>
</table>
<h2 id="why-the-php-client-barely-matters" class="heading-anchor">Why the PHP client barely matters<a class="anchor" href="#why-the-php-client-barely-matters" aria-label="Link to section: Why the PHP client barely matters">#</a></h2>
<p>A thread page makes about <strong>six</strong> cache calls. Here is the cost of one page, with the database on the local socket:</p>
<table>
	<thead>
			<tr>
					<th>Setup</th>
					<th>PHP CPU ms</th>
					<th>Valkey ms</th>
					<th>Valkey calls</th>
					<th>DB queries</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>A</td>
					<td>25.89</td>
					<td>0.274</td>
					<td>6.0</td>
					<td>10.7</td>
			</tr>
			<tr>
					<td>B</td>
					<td>26.00</td>
					<td>0.272</td>
					<td>6.0</td>
					<td>10.7</td>
			</tr>
			<tr>
					<td>C</td>
					<td>26.26</td>
					<td>0.307</td>
					<td>6.0</td>
					<td>10.7</td>
			</tr>
			<tr>
					<td>D</td>
					<td>25.52</td>
					<td>0.272</td>
					<td>6.0</td>
					<td>11.7</td>
			</tr>
			<tr>
					<td>E</td>
					<td>25.73</td>
					<td>0.004</td>
					<td>0</td>
					<td>14.8</td>
			</tr>
	</tbody>
</table>
<p>php-redis saves about <strong>0.03 ms</strong> of cache time per page, out of roughly 26 ms of PHP time. No client library can win much there.</p>
<p>A micro-benchmark of the two clients, run directly against the Valkey socket (median of 3 runs, µs per operation):</p>
<table>
	<thead>
			<tr>
					<th>Operation</th>
					<th>phpredis</th>
					<th>Credis</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>GET + unserialize, PHP serializer</td>
					<td>35.5</td>
					<td>37.6</td>
			</tr>
			<tr>
					<td>GET + unserialize, igbinary</td>
					<td>20.3</td>
					<td>22.5</td>
			</tr>
			<tr>
					<td>MGET × 20, PHP serializer</td>
					<td>55.1</td>
					<td>63.2</td>
			</tr>
			<tr>
					<td>MGET × 20, igbinary</td>
					<td>28.3</td>
					<td>35.3</td>
			</tr>
			<tr>
					<td>SET, igbinary</td>
					<td>13.4</td>
					<td>15.1</td>
			</tr>
			<tr>
					<td>connect + PING + close</td>
					<td>28.5</td>
					<td>31.5</td>
			</tr>
	</tbody>
</table>
<p>The serializer matters more than the client. igbinary nearly halves read cost with either library, and it shrank the sample cache entry from 7,907 bytes to 1,965. phpredis is only about 2 to 8 µs faster per call.</p>
<h2 id="why-the-cache-matters-more-with-a-remote-database" class="heading-anchor">Why the cache matters more with a remote database<a class="anchor" href="#why-the-cache-matters-more-with-a-remote-database" aria-label="Link to section: Why the cache matters more with a remote database">#</a></h2>
<p>On the Unix socket a query costs almost nothing. Skipping the cache saves a little PHP work, so the no-cache setup (E) actually comes out about 3% ahead.</p>
<p>The cache removes about four queries per page (14.8 down to 10.7). Once each query crosses a network, every one avoided saves a round trip. At 0.9 ms the cache is worth 4 to 6% of throughput. At 2.2 ms it is worth 15 to 20%, and single-request latency is up to 21% better.</p>
<p>The SV add-ons show the same pattern. XenForo&rsquo;s core provider (D) uses php-redis but drops the SV flood-check and view-counter add-ons, and adds about one query per page. With a local database that is free. At 2.2 ms D falls about 5 to 6% behind C on the forum, thread and mixed pages.</p>
<h2 id="one-false-alarm" class="heading-anchor">One false alarm<a class="anchor" href="#one-false-alarm" aria-label="Link to section: One false alarm">#</a></h2>
<p>The first home-page run with the 0.9 ms database showed 18.4 queries per request instead of the usual 14.3, which looked like a TCP-only code path. The three-round median for that page was back at 14.3, the same as over the local socket. It was a cold first pass after the switch, which is a good reason never to trust a single run.</p>
<h2 id="what-this-does-not-prove" class="heading-anchor">What this does not prove<a class="anchor" href="#what-this-does-not-prove" aria-label="Link to section: What this does not prove">#</a></h2>
<p>The result is narrow, and it is worth being explicit about where it stops:</p>
<ul>
<li><strong>One forum shape.</strong> Generated content, 64 logged-in members and 300 threads exercise the cache paths but not your add-on mix. A forum with heavy search, reactions or a chat add-on makes more queries per page, which changes how much the cache is worth.</li>
<li><strong>One host.</strong> CPU, RAM and disk were constant across setups, so the comparison isolates the cache clients. It says nothing about how the numbers scale down to a 2-vCPU VPS, where PHP time dominates even more.</li>
<li><strong>One database location.</strong> The remote cases simulate latency with <code>tc netem</code> and nothing else. A real remote database also adds CPU contention, connection resets and jitter.</li>
<li><strong>Guest traffic is excluded.</strong> Guests can be served from the web server&rsquo;s page cache, where PHP and the cache barely appear. The interesting case is members, so that is what was measured.</li>
<li><strong>Throughput, not tail latency.</strong> Median throughput over 20-second runs shows saturation behaviour. It is not a p99 study, and a cache miss storm under a cold start can look different.</li>
</ul>
<p>None of that changes the conclusion for a typical XenForo host — the client choice is noise next to whether the cache exists — but it is the boundary of the claim.</p>
<h2 id="choosing-a-setup" class="heading-anchor">Choosing a setup<a class="anchor" href="#choosing-a-setup" aria-label="Link to section: Choosing a setup">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Your situation</th>
					<th>Sensible default</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Fresh host, no existing XenForo config</td>
					<td>SV RedisCache with <code>php-igbinary</code>, no <code>php-redis</code></td>
			</tr>
			<tr>
					<td><code>config.php</code> selects the core <code>Redis</code> provider</td>
					<td>Install <code>php-redis</code>; the core provider requires it</td>
			</tr>
			<tr>
					<td>Database on a separate server</td>
					<td>Keep the cache on, keep the SV add-ons, and treat database latency as the first thing to fix</td>
			</tr>
			<tr>
					<td>Cache memory is the constraint</td>
					<td>Add <code>php-igbinary</code>; it cut a sample entry roughly 4×</td>
			</tr>
			<tr>
					<td>You are unsure what your host does now</td>
					<td>Measure the database round trip and the cache hit path before changing anything</td>
			</tr>
	</tbody>
</table>
<h2 id="what-i-changed" class="heading-anchor">What I changed<a class="anchor" href="#what-i-changed" aria-label="Link to section: What I changed">#</a></h2>
<p>Nothing, and that is the result. My provisioning script already:</p>
<ul>
<li>installs neither <code>php-redis</code> nor <code>php-igbinary</code> on a fresh server;</li>
<li>installs <code>php-redis</code> only when a XenForo <code>config.php</code> selects the core Redis provider, the one case that actually needs it.</li>
</ul>
<p>If you run XenForo with a separate database server:</p>
<ol>
<li><strong>Keep a cache on.</strong> SV RedisCache on a local Valkey socket is worth up to a fifth of your throughput at 2 ms database latency.</li>
<li><strong>Keep the SV add-ons.</strong> They remove database work the core provider does not.</li>
<li><strong>Don&rsquo;t install php-redis for speed.</strong> A 0 to 2% difference is inside normal run-to-run noise.</li>
<li><strong>Add php-igbinary if cache memory matters.</strong> It cuts the size of cache entries about 4× and needs no php-redis. Otherwise it is optional.</li>
<li><strong>Measure your own database round trip.</strong> Going from 0.9 ms to 2.2 ms cost more throughput than any cache choice here. Keeping the database server close to the web server is the biggest win available.</li>
</ol>
]]></content:encoded></item><item><title>Introducing Ubuntu Tips</title><link>https://ubuntips.com/posts/introducing-ubuntu-tips/</link><guid isPermaLink="true">https://ubuntips.com/posts/introducing-ubuntu-tips/</guid><pubDate>Sat, 21 Nov 2026 09:00:00 +0800</pubDate><dc:creator>Draft</dc:creator><description>A place to write down the things that took too long to figure out the first time.</description><category>Meta</category><content:encoded><![CDATA[<p>Most of the notes on this site started as comments in a shell script.</p>
<p>Provisioning an Ubuntu host is not hard, but it is full of decisions that are easy to get subtly wrong: the PHP-FPM process manager that looks fine at idle and collapses under load, the MariaDB buffer pool sized for a machine you no longer run, the sysctl values that only matter at 10,000 requests per second. Once you have worked them out, you write them down somewhere.</p>
<p>This blog is that &ldquo;somewhere&rdquo;. It is also an experiment in publishing: everything here is Markdown in a git repository, rendered by Hugo, and served as static files. No database, no admin panel, no plugin updates. The <a href="/posts/why-this-blog-is-a-static-site/">next post</a> explains that decision in detail.</p>
<h2 id="what-gets-published" class="heading-anchor">What gets published<a class="anchor" href="#what-gets-published" aria-label="Link to section: What gets published">#</a></h2>
<p>The posts fall into four rough categories:</p>
<ul>
<li><strong>Tuning notes.</strong> Why a value is what it is, what it costs, and how to check that it actually applied. A number without a verification step is a rumour.</li>
<li><strong>Build and provisioning.</strong> The design of the <a href="https://github.com/droplinxuser/ubuntu-setup-script">setup script</a> that installs and tunes the whole stack, including the parts that exist only to make reruns safe.</li>
<li><strong>Benchmarks with a method.</strong> Load tests are easy to make look convincing. Posts that include numbers also include the test bed, the order the setups ran in, and what was done to keep each run honest.</li>
<li><strong>Post-mortems.</strong> The change that looked safe in a dry run, the package that silently changed a default, the &ldquo;optimisation&rdquo; that was inside noise.</li>
</ul>
<p>Expect the occasional opinion, but the useful parts are the commands, the configuration, and the measurements.</p>
<h2 id="how-the-numbers-are-made" class="heading-anchor">How the numbers are made<a class="anchor" href="#how-the-numbers-are-made" aria-label="Link to section: How the numbers are made">#</a></h2>
<p>Benchmarks on this site come from one dedicated host: a 6-core/12-thread Xeon with 62 GB of RAM running Ubuntu 26.04, with Angie, PHP-FPM, MariaDB and Valkey installed and tuned by the same script the posts describe. Content is generated, the load generator is <a href="https://github.com/wg/wrk">wrk</a>, and run order is rotated so one setup does not always get the warm cache.</p>
<p>Two rules apply to every post with a table of results:</p>
<ol>
<li><strong>Medians, not best runs.</strong> Single runs are treated as anecdotes, because they are. One early home-page result in the XenForo post was 30% off until the three-round median brought it back in line.</li>
<li><strong>State the limits.</strong> A benchmark that simulates a remote database with <code>tc netem</code> measures network latency and nothing else. It does not reproduce a remote server&rsquo;s CPU, disk or jitter. Saying so is part of the result.</li>
</ol>
<p>Where a claim cannot be measured on this hardware, the post says so rather than extrapolating.</p>
<h2 id="how-the-site-is-built" class="heading-anchor">How the site is built<a class="anchor" href="#how-the-site-is-built" aria-label="Link to section: How the site is built">#</a></h2>
<p>The workflow is deliberately boring:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># write a post</span>
</span></span><span class="line"><span class="cl">hugo new content posts/some-topic.md
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># preview</span>
</span></span><span class="line"><span class="cl">hugo server
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># publish</span>
</span></span><span class="line"><span class="cl">git add -A <span class="o">&amp;&amp;</span> git commit -m <span class="s2">&#34;post: some topic&#34;</span> <span class="o">&amp;&amp;</span> git push
</span></span></code></pre></div><p>A push to <code>main</code> triggers GitHub Actions, which builds the site and deploys it to GitHub Pages. Social cards, sitemap and structured data are generated in the same run. The whole build takes seconds, and the published output is a directory of HTML, CSS and images.</p>
<p>This also means the site has no runtime to patch. There is no login to brute-force, no query string to inject into, and no upload directory to leave executable. For a blog about server hardening, that felt like the minimum bar.</p>
<h2 id="what-you-will-not-find" class="heading-anchor">What you will not find<a class="anchor" href="#what-you-will-not-find" aria-label="Link to section: What you will not find">#</a></h2>
<ul>
<li><strong>Comments.</strong> If you want to reply, email or open an issue on the repository. Moderation queues are a hobby I am not taking up.</li>
<li><strong>A newsletter popup.</strong> The <a href="/index.xml">RSS feed</a> is the subscription mechanism.</li>
<li><strong>Tracking scripts.</strong> No analytics, no third-party fonts, no embeds that phone home.</li>
<li><strong>Sponsored posts.</strong> If that ever changes, the post will say so at the top.</li>
</ul>
<h2 id="corrections" class="heading-anchor">Corrections<a class="anchor" href="#corrections" aria-label="Link to section: Corrections">#</a></h2>
<p>If a command is wrong, a value is stale, or a measurement does not reproduce, the fix is a pull request or an issue on the repository. Posts are versioned in git, so the history of a correction is public, which is more than most blogs can say.</p>
<h2 id="following-along" class="heading-anchor">Following along<a class="anchor" href="#following-along" aria-label="Link to section: Following along">#</a></h2>
<p>Subscribe to the <a href="/index.xml">RSS feed</a> and you will get new posts without an algorithm deciding what you see. Start with <a href="/posts/why-this-blog-is-a-static-site/">why this blog is a static site</a> and <a href="/posts/one-idempotent-script/">the one idempotent script</a> if you want the two ideas the rest of the site builds on.</p>
]]></content:encoded></item><item><title>Why this blog is a static site</title><link>https://ubuntips.com/posts/why-this-blog-is-a-static-site/</link><guid isPermaLink="true">https://ubuntips.com/posts/why-this-blog-is-a-static-site/</guid><pubDate>Fri, 20 Nov 2026 18:30:00 +0800</pubDate><dc:creator>Draft</dc:creator><description>No database, no admin panel, nothing to patch. Here is the trade-off.</description><category>Hugo</category><category>Static-Site</category><category>Security</category><content:encoded><![CDATA[<p>A blog about hardening servers should not itself be the softest target in the stack. That ruled out the obvious choice.</p>
<h2 id="the-requirements" class="heading-anchor">The requirements<a class="anchor" href="#the-requirements" aria-label="Link to section: The requirements">#</a></h2>
<p>The site needed to do five things:</p>
<ul>
<li>publish Markdown posts with syntax highlighting and tables,</li>
<li>load fast on a phone over a mediocre connection,</li>
<li>have nothing that needs a security patch on a Tuesday night,</li>
<li>cost approximately nothing to run,</li>
<li>keep every post in git, so a local agent or a shell script can edit it as easily as a person.</li>
</ul>
<p>That last point matters more than it sounds. If the source of truth is a database, every change has to go through an API, an admin session or a migration. If it is a directory of text files, an editor, a script and a coding agent all work the same way.</p>
<h2 id="what-a-conventional-blog-engine-costs" class="heading-anchor">What a conventional blog engine costs<a class="anchor" href="#what-a-conventional-blog-engine-costs" aria-label="Link to section: What a conventional blog engine costs">#</a></h2>
<p>A typical CMS stack is a language runtime, a database, a web admin, a plugin ecosystem and a theme. Each of those is a component that can be exploited, and each has its own release cadence:</p>
<table>
	<thead>
			<tr>
					<th>Component</th>
					<th>Typical failure mode</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Runtime (PHP, Node)</td>
					<td>RCE in a dependency reachable from a request path</td>
			</tr>
			<tr>
					<td>Database</td>
					<td>Credential leak, SQL injection, unpatched service exposed on a socket</td>
			</tr>
			<tr>
					<td>Admin panel</td>
					<td>Brute force, stolen session, vulnerable plugin endpoint</td>
			</tr>
			<tr>
					<td>Upload directory</td>
					<td>A file that ends in <code>.php</code> and gets executed</td>
			</tr>
			<tr>
					<td>Plugins and themes</td>
					<td>Abandoned code, supply-chain compromise</td>
			</tr>
			<tr>
					<td>Search add-on</td>
					<td>Index corruption, another service to keep running</td>
			</tr>
	</tbody>
</table>
<p>None of this is hypothetical; it is the ordinary background noise of running WordPress. The response is a patch routine, a WAF and monitoring. For a blog that changes a few times a month, that is a lot of machinery protecting text.</p>
<h2 id="what-a-static-site-removes" class="heading-anchor">What a static site removes<a class="anchor" href="#what-a-static-site-removes" aria-label="Link to section: What a static site removes">#</a></h2>
<p>The published site is a directory of files. A request is a file read. Concretely, this site has:</p>
<ul>
<li>no database and no database credentials,</li>
<li>no login form, session cookie or password reset flow,</li>
<li>no upload endpoint and no writable web root,</li>
<li>no server-side includes, no template evaluated per request,</li>
<li>no third-party JavaScript, fonts, or analytics.</li>
</ul>
<p>The attack surface is the CDN serving files, plus whatever is in this repository. A compromised post can change text; it cannot pivot into a database.</p>
<h2 id="the-pipeline" class="heading-anchor">The pipeline<a class="anchor" href="#the-pipeline" aria-label="Link to section: The pipeline">#</a></h2>
<p><code>hugo.toml</code> (site config, menus, output formats) plus <code>content/posts/*.md</code> is the input. A push to <code>main</code> runs <code>.github/workflows/pages.yml</code>:</p>
<ol>
<li>install the pinned Hugo version,</li>
<li>build once to produce <code>public/index.json</code>,</li>
<li>render a 1200×630 social card per post with headless Chrome,</li>
<li>build the final site (minified, fingerprinted assets),</li>
<li>upload the artifact and deploy it to GitHub Pages.</li>
</ol>
<p>The build is a few seconds, and the same commands work locally:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">hugo new content posts/some-topic.md   <span class="c1"># from the archetype</span>
</span></span><span class="line"><span class="cl">hugo server                            <span class="c1"># http://localhost:1313</span>
</span></span><span class="line"><span class="cl">hugo --minify --gc                     <span class="c1"># what CI runs</span>
</span></span></code></pre></div><p>Because the output is static, rollbacks are trivial: revert the commit, push, and the previous version is live again in under a minute. There is no migration and no cache to flush beyond the CDN&rsquo;s own.</p>
<h2 id="search-without-a-server" class="heading-anchor">Search without a server<a class="anchor" href="#search-without-a-server" aria-label="Link to section: Search without a server">#</a></h2>
<p>Removing the database also removes the search backend, which is where most &ldquo;you cannot do that statically&rdquo; arguments start. Hugo can emit every post as JSON:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span> <span class="nt">&#34;title&#34;</span><span class="p">:</span> <span class="s2">&#34;...&#34;</span><span class="p">,</span> <span class="nt">&#34;url&#34;</span><span class="p">:</span> <span class="s2">&#34;/posts/...&#34;</span><span class="p">,</span> <span class="nt">&#34;date&#34;</span><span class="p">:</span> <span class="s2">&#34;...&#34;</span><span class="p">,</span> <span class="nt">&#34;tags&#34;</span><span class="p">:</span> <span class="p">[</span><span class="err">...</span><span class="p">],</span> <span class="nt">&#34;markdown&#34;</span><span class="p">:</span> <span class="s2">&#34;...&#34;</span> <span class="p">}</span>
</span></span></code></pre></div><p>That file is fetched only when the search box is focused, then filtered in the browser. It is not a full-text index — it is a few kilobytes per post and a <code>String.includes</code> — but for a blog of this size it returns results instantly and has zero operational cost. At a few thousand posts you would move to a prebuilt index such as Pagefind; the rest of the pipeline would not change.</p>
<h2 id="the-trade-offs-honestly" class="heading-anchor">The trade-offs, honestly<a class="anchor" href="#the-trade-offs-honestly" aria-label="Link to section: The trade-offs, honestly">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Static site</th>
					<th>Conventional CMS</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>No in-browser editor by default</td>
					<td>Rich admin UI</td>
			</tr>
			<tr>
					<td>Rebuild required for every change</td>
					<td>Instant publish</td>
			</tr>
			<tr>
					<td>Comments need a third party</td>
					<td>Built in</td>
			</tr>
			<tr>
					<td>Nothing to patch</td>
					<td>Patch treadmill</td>
			</tr>
			<tr>
					<td>Search is client-side</td>
					<td>Search server included</td>
			</tr>
			<tr>
					<td>Preview is local or a branch deploy</td>
					<td>Preview is built in</td>
			</tr>
	</tbody>
</table>
<p>Each of those has a workaround: a git-based CMS for browser editing, a hosted comment service, Pagefind for search. What you cannot get back is the single-process simplicity of a CMS, where writing a post is one form submission.</p>
<h2 id="caching-and-the-limit-of-github-pages" class="heading-anchor">Caching, and the limit of GitHub Pages<a class="anchor" href="#caching-and-the-limit-of-github-pages" aria-label="Link to section: Caching, and the limit of GitHub Pages">#</a></h2>
<p>Assets are minified and fingerprinted (<code>style.min.&lt;hash&gt;.css</code>), so a deploy produces new URLs and no browser can serve stale CSS. That part is solved by the build.</p>
<p>Response headers are not. GitHub Pages sends <code>cache-control: max-age=600</code> for everything and ignores <code>_headers</code> files. The repository still carries a <code>static/_headers</code> with the policy this site wants — HTML revalidated, hashed assets immutable, images cached for a week — because it works unchanged on Cloudflare Pages. To get that policy in front of GitHub Pages you would proxy the DNS records through Cloudflare and add cache rules; the <a href="https://github.com/droplinxuser/ubuntips">README</a> describes both paths.</p>
<p>It is worth being precise about what that costs: ten minutes of cache lifetime on HTML, not a correctness problem. The fingerprinted asset names mean the worst case is a slightly stale homepage, not a broken stylesheet.</p>
<h2 id="when-a-static-site-is-the-wrong-choice" class="heading-anchor">When a static site is the wrong choice<a class="anchor" href="#when-a-static-site-is-the-wrong-choice" aria-label="Link to section: When a static site is the wrong choice">#</a></h2>
<p>This setup is a bad fit if any of these are true:</p>
<ul>
<li><strong>Non-technical authors.</strong> If nobody on the team wants to touch git, a CMS is the honest answer.</li>
<li><strong>Frequent, tiny edits.</strong> Rebuilding and pushing for a typo fix is fine; doing it fifty times a day is not.</li>
<li><strong>Per-user content.</strong> Comments, memberships, dashboards and personalisation need a runtime.</li>
<li><strong>Search over a large corpus.</strong> Client-side filtering stops scaling; you need an index service.</li>
<li><strong>A publication with a workflow.</strong> Draft review, scheduled publishing and roles are all things a CMS already solved.</li>
</ul>
<h2 id="what-it-costs-to-run" class="heading-anchor">What it costs to run<a class="anchor" href="#what-it-costs-to-run" aria-label="Link to section: What it costs to run">#</a></h2>
<p>GitHub Pages serves the site and the certificate for free. The repository holds the source; Actions builds it. There is no VPS, no database volume, no backup job — the backup is <code>git clone</code>.</p>
<p>The failure modes are equally small: a bad build fails before deploy, a bad deploy is reverted with one commit, and if the host disappeared tomorrow the whole site would be rebuildable from the repository in minutes.</p>
<p>That is the trade: a little friction when publishing, in exchange for almost nothing to operate. For a blog that is mostly read rather than written, it is the right side of the deal.</p>
]]></content:encoded></item><item><title>One idempotent script for the whole Ubuntu web stack</title><link>https://ubuntips.com/posts/one-idempotent-script/</link><guid isPermaLink="true">https://ubuntips.com/posts/one-idempotent-script/</guid><pubDate>Wed, 18 Nov 2026 10:15:00 +0800</pubDate><dc:creator>Draft</dc:creator><description>Angie, PHP-FPM, MariaDB, Valkey and Elasticsearch from a single Bash entry point: every command, option and safety rule in one place.</description><category>Ubuntu</category><category>Automation</category><category>Bash</category><content:encoded><![CDATA[<p>The setup script behind most of these notes has one rule: every run must be safe to repeat. That constraint shapes the whole design, and it is the part most provisioning scripts get wrong.</p>
<p>This post is the long version of the script&rsquo;s README: what it installs, what each flag does, what it refuses to touch, and how to verify a host afterwards. The source is at <a href="https://github.com/droplinxuser/ubuntu-setup-script">droplinxuser/ubuntu-setup-script</a>.</p>
<h2 id="why-idempotence-is-the-hard-part" class="heading-anchor">Why idempotence is the hard part<a class="anchor" href="#why-idempotence-is-the-hard-part" aria-label="Link to section: Why idempotence is the hard part">#</a></h2>
<p>A script that only has to work once can do almost anything: append to a file, create a user, restart a service, assume the default config is still there. The second run is where the trouble starts. Appending twice duplicates a directive. Creating a user that already exists may reset its groups. Restarting a service in the middle of a config write can leave it running on half a file.</p>
<p>The usual failure is quieter than an error message. It is <em>drift</em>: the server installed six months ago and patched twice no longer matches the one installed yesterday, and nothing in the repository describes the difference. The next person to touch it is guessing.</p>
<p>So the script separates <em>recording</em> from <em>changing</em>, makes every write derived rather than appended, and gives every operation a preview.</p>
<h2 id="requirements" class="heading-anchor">Requirements<a class="anchor" href="#requirements" aria-label="Link to section: Requirements">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Item</th>
					<th>Detail</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>OS</td>
					<td>Ubuntu <strong>26.04 LTS or newer</strong> for installs; <code>--optimize</code>, <code>--upgrade-php</code>, <code>--diagnostics</code> and <code>--restart-all</code> also accept 22.04 and 24.04</td>
			</tr>
			<tr>
					<td>Shell</td>
					<td>Bash 4.4+, root</td>
			</tr>
			<tr>
					<td>Network</td>
					<td>Ubuntu, Angie, Sury, Elastic and NodeSource repositories, plus GitHub for the web-server config tree (or a local checkout)</td>
			</tr>
			<tr>
					<td>Resources</td>
					<td>Elasticsearch needs ~1.5 GB of disk plus its heap; MariaDB its buffer pool; PHP one static worker per <code>pm.max_children</code> slot</td>
			</tr>
	</tbody>
</table>
<p>A host can only run <strong>one PHP-FPM version</strong> at a time: Angie and the pool both use <code>/run/php/php-fpm.sock</code>. Changing versions is what <code>--upgrade-php</code> is for; <code>--php ver=X</code> is a first installation and refuses to replace a version that is already there.</p>
<h2 id="the-command-surface" class="heading-anchor">The command surface<a class="anchor" href="#the-command-surface" aria-label="Link to section: The command surface">#</a></h2>
<p><code>--basic</code> is required for every install, and all of its values are optional. Only the services named on the command line are touched.</p>
<table>
	<thead>
			<tr>
					<th>Command</th>
					<th>Purpose</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>--basic [server=] [host=] [swap=] [time=]</code></td>
					<td>OS baseline; required for every install</td>
			</tr>
			<tr>
					<td><code>--angie [anubis=yes|no]</code></td>
					<td>Angie web server, config tree, optional Anubis bot filter</td>
			</tr>
			<tr>
					<td><code>--php [ver=] [children=] [max_requests=]</code></td>
					<td>PHP-FPM</td>
			</tr>
			<tr>
					<td><code>--mariadb user= pass= [size=] [bind=]</code></td>
					<td>MariaDB</td>
			</tr>
			<tr>
					<td><code>--valkey [ram=] [policy=] [io_threads=]</code></td>
					<td>Valkey cache</td>
			</tr>
			<tr>
					<td><code>--elastic [host=] [ram=]</code></td>
					<td>Elasticsearch</td>
			</tr>
			<tr>
					<td><code>--others ITEM... | all</code></td>
					<td>helper packages</td>
			</tr>
			<tr>
					<td><code>--domain DOMAIN [app=] [db=] [user=] [pass=] [sql=]</code></td>
					<td>vhost, certificate, optional database</td>
			</tr>
			<tr>
					<td><code>--optimize [anubis=yes|no]</code></td>
					<td>tune the OS and every installed service in place</td>
			</tr>
			<tr>
					<td><code>--upgrade-php=X.Y</code></td>
					<td>replace the installed PHP version in place</td>
			</tr>
			<tr>
					<td><code>--diagnostics</code></td>
					<td>write a redacted, read-only report</td>
			</tr>
			<tr>
					<td><code>--restart-all</code></td>
					<td>ordered restart of every active service</td>
			</tr>
			<tr>
					<td><code>--purge [TARGET...]</code></td>
					<td>stop and disable services, restore recorded settings</td>
			</tr>
			<tr>
					<td><code>--dry-run</code> / <code>--check</code></td>
					<td>print the plan, change nothing; works with every command</td>
			</tr>
	</tbody>
</table>
<p>A full install looks like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo bash setup.sh <span class="se">\
</span></span></span><span class="line"><span class="cl">  --basic <span class="nv">server</span><span class="o">=</span>dedi <span class="nv">host</span><span class="o">=</span>web1.example.com <span class="nv">time</span><span class="o">=</span>Asia/Manila <span class="nv">swap</span><span class="o">=</span>8G <span class="se">\
</span></span></span><span class="line"><span class="cl">  --angie --php <span class="nv">ver</span><span class="o">=</span>8.5 <span class="se">\
</span></span></span><span class="line"><span class="cl">  --mariadb <span class="nv">user</span><span class="o">=</span>demo <span class="nv">pass</span><span class="o">=</span>temp <span class="nv">size</span><span class="o">=</span>auto <span class="nv">bind</span><span class="o">=</span>127.0.0.1 <span class="se">\
</span></span></span><span class="line"><span class="cl">  --valkey --elastic <span class="nv">host</span><span class="o">=</span>localhost <span class="nv">ram</span><span class="o">=</span>4g --others all
</span></span></code></pre></div><p>&hellip;and a minimal one like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo bash setup.sh --basic --angie --php
</span></span></code></pre></div><h2 id="--basic" class="heading-anchor"><code>--basic</code><a class="anchor" href="#--basic" aria-label="Link to section: --basic">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Default</th>
					<th>Effect</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>server=dedi|vps</code></td>
					<td>auto-detect</td>
					<td>install-time hint; <code>dedi</code> sets the <code>performance</code> CPU governor. <code>--optimize</code> re-detects the class from the hardware</td>
			</tr>
			<tr>
					<td><code>host=FQDN</code></td>
					<td><code>&lt;threads&gt;c-&lt;RAM&gt;g-&lt;storage&gt;</code></td>
					<td>hostname via <code>hostnamectl</code>; a repeat run without <code>host=</code> keeps the current name</td>
			</tr>
			<tr>
					<td><code>swap=SIZE</code></td>
					<td>only when total swap is 0 or below half of RAM</td>
					<td><code>/swapfile</code> of exactly that size, capped at half of RAM</td>
			</tr>
			<tr>
					<td><code>time=REGION/CITY</code></td>
					<td><code>Asia/Manila</code></td>
					<td>timezone; a repeat run without <code>time=</code> keeps the current zone</td>
			</tr>
			<tr>
					<td><code>mitigations=off|on</code></td>
					<td>not touched</td>
					<td>adds/removes <code>mitigations=off</code> in a managed GRUB drop-in; effective at the next reboot, and the run checks the generated boot menu actually carries it</td>
			</tr>
	</tbody>
</table>
<p><code>mitigations=off</code> is measured and tempting, and it is also a real trade: it removes the kernel&rsquo;s protection between local processes. The README is explicit that it belongs on hosts where only you run code — one key-only administrator, no shared hosting, no untrusted local users.</p>
<p><code>--basic</code> changes hostname, resolver, sysctls, limits, firewall and timezone. The repository&rsquo;s own advice is to test it on a disposable server first; that is not boilerplate.</p>
<h2 id="angie" class="heading-anchor">Angie<a class="anchor" href="#angie" aria-label="Link to section: Angie">#</a></h2>
<p><code>--angie [anubis=yes|no]</code>.</p>
<ul>
<li>Installs <code>angie</code> and <code>angie-module-brotli</code>.</li>
<li>Deploys the configuration tree from a <strong>separate repository</strong> (<code>server-configs-nginx</code>) with its own deployer; <code>CONFIG_SOURCE_DIR=/path</code> uses a local checkout, <code>CONFIG_REPO_URL</code>/<code>CONFIG_REPO_REF</code> select a fork or branch.</li>
<li>Applies the hardware profile and guest caches through the same <code>angie_apply_profile</code> that <code>--optimize</code> uses.</li>
<li>Ships systemd <code>LimitNOFILE</code> and <code>/etc/default/angie</code>, generates <code>http.d/cloudflare.conf</code>, restarts the service.</li>
</ul>
<p>Guest caches for WordPress and XenForo report their state in a single <code>X-Cache-Status</code> header (<code>HIT</code>, <code>MISS</code>, <code>BYPASS</code>, <code>EXPIRED</code>). Cached locations disable per-hit AIO and Brotli on purpose: the body is already compressed, so re-running either filter only costs CPU.</p>
<p>An upstream that a deployed vhost still references but the canonical tree no longer defines is preserved in <code>http.d/zz-setup-preserved-upstreams.conf</code> instead of letting <code>angie -t</code> fail with &ldquo;host not found in upstream&rdquo;. The include is regenerated each run and retired once the repository defines the name again.</p>
<h3 id="anubis-optionally" class="heading-anchor">Anubis, optionally<a class="anchor" href="#anubis-optionally" aria-label="Link to section: Anubis, optionally">#</a></h3>
<p><code>--angie anubis=yes</code> puts a bot filter in front of every site. It is not installed unless asked for, works on fresh and existing hosts, and <code>--optimize anubis=no</code> restores direct TLS, removes the generated Angie files and stops/disables the service while keeping the binary for a fast re-enable.</p>
<h2 id="php-fpm" class="heading-anchor">PHP-FPM<a class="anchor" href="#php-fpm" aria-label="Link to section: PHP-FPM">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Default</th>
					<th>Effect</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>ver=X.Y</code></td>
					<td>newest Sury build</td>
					<td>version to install</td>
			</tr>
			<tr>
					<td><code>children=auto|N</code></td>
					<td>auto</td>
					<td><code>pm.max_children</code>; an explicit value wins</td>
			</tr>
			<tr>
					<td><code>max_requests=N</code></td>
					<td>threads × 1024</td>
					<td>recycle a worker after N requests</td>
			</tr>
	</tbody>
</table>
<p>The pool is always <code>pm = static</code>. The worker count is logical CPUs × a factor chosen by storage and topology:</p>
<table>
	<thead>
			<tr>
					<th>Situation</th>
					<th>Workers per CPU</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Local MariaDB on flash</td>
					<td>1.0</td>
			</tr>
			<tr>
					<td>Shared/virtual CPU, or a remote database</td>
					<td>1.5</td>
			</tr>
			<tr>
					<td>Spinning disks</td>
					<td>2.0</td>
			</tr>
	</tbody>
</table>
<p>That is then capped by the shared-memory plan (at most RAM/2 at 96 MB per worker, 512 maximum). The measured advice is blunt: on the 16-thread audit host, 16 workers did 834 req/s and 32 workers did 808 req/s — extra workers only contend for the same cores.</p>
<p>Also managed: <code>request_terminate_timeout 300s</code>, slow log at 10 s, <code>rlimit_files 524288</code>, systemd <code>LimitNOFILE=524288</code>, <code>UMask=0027</code>, and <code>KillSignal=SIGQUIT</code> so a restart closes persistent MariaDB connections gracefully instead of logging &ldquo;Aborted connection&rdquo; warnings.</p>
<p><code>php.ini</code> gets <code>memory_limit</code> 256–512M (128M under 2 GB RAM), OPcache 128–512 MB with interned strings, a 4–16 MB realpath cache, and JIT <strong>always tracing</strong>, with the buffer at OPcache/8. There is no JIT mode switch; an old <code>SETUP_PHP_JIT</code> value is ignored with a notice. Measured: tracing beat JIT-off by 5% on XenForo members, <code>function</code> mode lost 6–8%, and a 256 MB buffer was slower than 64 or 128 MB.</p>
<p>Extensions default to the XenForo profile: <code>fpm cli opcache mysql gd curl xml zip gmp mbstring</code>. <strong>No <code>redis</code>/<code>igbinary</code> by default</strong> — XenForo runs on SV RedisCache&rsquo;s pure-PHP client, and WordPress runs without an object-cache drop-in. <code>--domain</code> installs what an app cannot run without (Chevereto pulls <code>redis</code>/<code>igbinary</code> and <code>imagick</code>); <code>--upgrade-php</code> carries whatever the old version had.</p>
<p>The PHP step also repairs the web server: <code>fastcgi_param PATH_TRANSLATED</code> in every <code>h5bp/php*.conf</code>, and it comments out per-request <code>PHP_ADMIN_VALUE open_basedir</code> — PHP-FPM caches admin values per worker, so one vhost&rsquo;s setting otherwise leaks onto every other vhost in the shared pool.</p>
<h2 id="mariadb" class="heading-anchor">MariaDB<a class="anchor" href="#mariadb" aria-label="Link to section: MariaDB">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Default</th>
					<th>Effect</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>user=U</code></td>
					<td>required</td>
					<td>admin user for <code>localhost</code>, <code>127.0.0.1</code> and <code>::1</code> (needed with <code>skip_name_resolve</code>)</td>
			</tr>
			<tr>
					<td><code>pass=P</code></td>
					<td>required</td>
					<td>also written to <code>/etc/mysqlbkup.cnf</code>, mode 600</td>
			</tr>
			<tr>
					<td><code>size=auto|4gb</code></td>
					<td>auto</td>
					<td>buffer pool = live data+index +5%, 128 MB minimum, capped at 80% of RAM when MariaDB is the only data service, otherwise half</td>
			</tr>
			<tr>
					<td><code>bind=ADDR[,ADDR...]</code></td>
					<td><code>127.0.0.1</code></td>
					<td>loopback by default; <code>IPV4</code> resolves the public address. TCP 3306 is never opened in the firewall</td>
			</tr>
	</tbody>
</table>
<p>The interesting part is <code>size=auto</code>. It measures the live data, so an empty database gets 128 MB and a database that grew gets a larger pool — and a pool that is more than one step above its target is shrunk online rather than holding RAM the data does not use. That is why the README tells you to run <code>--optimize</code> again after a large <code>sql=</code> import: the plan is re-measured, not guessed.</p>
<p>The hardware profile sets the redo log to a quarter of the pool, I/O capacity by disk type (NVMe 10000/20000, SSD 4000/8000, HDD 400/800), <code>thread_handling=pool-of-threads</code>, <code>max_connections</code> at PHP workers × 1.25 + 50, table caches, temp tables, <code>flush_log_at_trx_commit=2</code>, and slow/error logs under <code>/var/www/logs/mariadb/</code>.</p>
<p>Validation matters more than any of these values: generated files are checked with <code>mariadbd --help --verbose</code> before any restart. The install also embeds <code>mysqltuner.pl</code> and a <code>mysqlbackup</code> utility that keeps 30 dumps.</p>
<p>A less obvious base setting: <code>innodb_snapshot_isolation = 0</code>, so <code>REPEATABLE READ</code> keeps MySQL&rsquo;s behaviour and XenForo does not hit MariaDB error 1020.</p>
<h2 id="valkey" class="heading-anchor">Valkey<a class="anchor" href="#valkey" aria-label="Link to section: Valkey">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Option</th>
					<th>Default</th>
					<th>Effect</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>ram=SIZE</code></td>
					<td>data +20%, 128 MB minimum</td>
					<td><code>maxmemory</code>; an explicit value is used verbatim</td>
			</tr>
			<tr>
					<td><code>policy=NAME</code></td>
					<td><code>allkeys-lru</code></td>
					<td><code>maxmemory-policy</code></td>
			</tr>
			<tr>
					<td><code>io_threads=N</code></td>
					<td>1</td>
					<td>extra socket I/O threads</td>
			</tr>
	</tbody>
</table>
<p>Managed config: loopback <code>bind</code>, <code>protected-mode</code>, a Unix socket at <code>/run/valkey/valkey.sock</code> (mode 770, <code>www-data</code> in the <code>valkey</code> group), <code>save &quot;&quot;</code>, <code>appendonly no</code>, <code>maxclients</code> at PHP workers × 4 + 2000 (minimum 10000), and <code>hz 10</code>.</p>
<p>Two operational notes:</p>
<ul>
<li>With <code>redis-server</code> installed, <code>--valkey</code> is <strong>skipped with a warning</strong> and <code>--optimize</code> tunes the existing Redis with the same profile. If both exist, Valkey wins.</li>
<li>Runtime values are applied with <code>CONFIG SET</code>; a restart (which empties the cache) happens only for startup-only keys. On a cache that is allowed to evict, filling its maxmemory is normal, not a reason to shrink it.</li>
</ul>
<h2 id="elasticsearch" class="heading-anchor">Elasticsearch<a class="anchor" href="#elasticsearch" aria-label="Link to section: Elasticsearch">#</a></h2>
<p><code>--elastic [host=] [ram=]</code>. Defaults to <code>localhost</code> and <code>auto</code> heap: index store/4 rounded to 512 MB, between 512 MB and 25% of RAM, 31 GB ceiling.</p>
<p>Managed: single-node discovery, X-Pack security off (keep it off unless you have TLS and a firewall), <code>bootstrap.memory_lock</code>, thread pools sized from CPUs, a 200 MB content limit, <code>vm.max_map_count</code>, and — when the index fits in the memory plan — <code>index.store.preload: [&quot;*&quot;]</code>, so index files are loaded at open rather than on first query.</p>
<p>It also fixes the yellow health a single node reports because of unassigned replicas, by setting replicas to 0 plus a low-priority template. A probe endpoint follows <code>http.host</code>/<code>network.host</code>/<code>http.port</code> if you change them.</p>
<h2 id="others-and-domains" class="heading-anchor">Others and domains<a class="anchor" href="#others-and-domains" aria-label="Link to section: Others and domains">#</a></h2>
<p><code>--others</code> takes one or more of <code>smartmon</code>, <code>nvme</code>, <code>gif</code>, <code>nodejs</code>, <code>sysstat</code>, or <code>all</code>. Node.js comes from NodeSource with the major pinned by <code>SETUP_NODE_MAJOR</code> (default 26); an installed major is never switched silently, because the native-addon ABI changes.</p>
<p><code>--domain</code> is standalone but needs Angie (and MariaDB when <code>db=</code> is given), can be repeated, and supports these vhost templates: <code>basic</code>, <code>xf</code>, <code>wordpress</code>, <code>flarum</code>, <code>pingvin</code>, <code>chevereto</code>, <code>polr</code>, <code>lychee</code>, <code>shlink</code>, <code>sfs</code>, <code>php</code>, <code>node</code>.</p>
<p>It creates the document root (<code>/var/www/&lt;domain&gt;/public</code>), a self-signed certificate under <code>/etc/angie/ssl/&lt;domain&gt;/</code>, and a vhost tested with <code>angie -t</code>. Existing vhosts and databases are preserved, and application code is not installed. A dump import runs only into an empty database, and a dump carrying its own <code>CREATE DATABASE</code>/<code>USE</code> for another schema is refused before anything loads.</p>
<p>A domain install ends with the same tuning pass <code>--optimize</code> performs, because a new vhost changes the plan: the PHP worker cap, OPcache file budget, guest cache, and the managed wp-cron / XenForo job entries.</p>
<h2 id="the-security-pass" class="heading-anchor">The security pass<a class="anchor" href="#the-security-pass" aria-label="Link to section: The security pass">#</a></h2>
<p>Every <code>--basic</code> and <code>--optimize</code> run includes hardening aimed at the web root:</p>
<ul>
<li><strong>WordPress:</strong> <code>wp-config.php</code> owned <code>root:www-data</code> at mode 640, <code>DISALLOW_FILE_EDIT</code> and <code>DISALLOW_FILE_MODS</code>, <code>DISABLE_WP_CRON</code> with a managed cron entry, <code>WP_DEBUG_DISPLAY=false</code>, <code>FORCE_SSL_ADMIN</code>, placeholder salts replaced, and a globally privileged <code>DB_USER</code> narrowed to its own database.</li>
<li><strong>Malware:</strong> known webshells quarantined under <code>/var/lib/setup-quarantine/</code>; suspicious admins, risky plugins, world-writable files and oversized archives reported.</li>
<li><strong>APT:</strong> every third-party repository pinned to its own <code>signed-by</code> keyring, so one vendor&rsquo;s key cannot validate another vendor&rsquo;s package.</li>
<li><strong>Audit:</strong> reports SSH password authentication, public 80/443 and a non-loopback Elasticsearch.</li>
</ul>
<p>SSH hardening, brute-force protection and origin-only firewalling are left to the operator on purpose. They depend on how a host is reached — bastion, VPN, provider firewall — and a script guessing wrong there locks people out.</p>
<h2 id="--optimize-and-parity-with-install" class="heading-anchor"><code>--optimize</code>, and parity with install<a class="anchor" href="#--optimize-and-parity-with-install" aria-label="Link to section: --optimize, and parity with install">#</a></h2>
<p><code>--optimize</code> tunes the OS and every installed service in place on 22.04, 24.04 and 26.04. It <strong>never installs, starts or purges a managed service</strong>, and never touches swap, the resolver or the firewall. The only package it may add is <code>angie-module-brotli</code> (plus Anubis when asked), and the only one it may remove is certbot, once nothing uses it.</p>
<p>Angie is synced from the config repository and tested; the service is reloaded <strong>once, and only when the tree digest changed</strong>. A failed sync or test restores the previous tree and unit drop-in. Every application guest cache reports through the same <code>X-Cache-Status</code> header.</p>
<p>For Cloudflare-proxied sites (SSL mode <em>Full</em>), it can move a vhost off certbot to the host&rsquo;s self-signed default pair. That only happens when every name in the server block is an exact host name resolving solely to Cloudflare; a wildcard or regex name keeps the block where it is. The change is then proven by a probe that must echo fresh digits through Cloudflare before the vhost is accepted — a cached answer, a challenge or a 526 is not proof. Without proof, the vhost is restored byte for byte.</p>
<p>The property that makes this trustworthy is a test, not a promise: <strong>a fresh install followed by <code>--optimize</code> produces the same configuration, byte-for-byte.</strong> That catches ordering, whitespace, file-mode and include-order differences a human would miss, and it means &ldquo;install, then optimize&rdquo; is a safe way to learn the script.</p>
<h2 id="--upgrade-php" class="heading-anchor"><code>--upgrade-php</code><a class="anchor" href="#--upgrade-php" aria-label="Link to section: --upgrade-php">#</a></h2>
<p><code>--upgrade-php=X.Y</code> replaces PHP in place. It is standalone and cannot be combined with install flags, <code>--optimize</code>, <code>--purge</code>, <code>--diagnostics</code>, <code>--restart-all</code> or <code>--domain</code>.</p>
<p>The order is what makes it safe:</p>
<ol>
<li><strong>Snapshot</strong> every PHP package, extension, <code>apt-mark</code> state, operator <code>.ini</code>, extra pool and the old <code>/etc/php</code> tree under <code>/var/lib/setup.sh/</code>.</li>
<li><strong>Preflight the applications.</strong> It detects WordPress, XenForo and Chevereto roots (including a Redis object-cache drop-in and a XenForo <code>config.php</code> that selects the core Redis provider) and checks the target repository for every hard requirement. If a site would lose an extension, it stops <strong>before the purge</strong>, with PHP still serving. <code>SETUP_PHP_ALLOW_MISSING_EXT=1</code> accepts the loss explicitly.</li>
<li><strong>Purge</strong>, then <strong>install</strong> the target and map every old extension. An extension the new release has not published is reported and retried by the next upgrade; core PHP still installs.</li>
<li><strong>Migrate</strong> operator ini files and extra pools, validate with <code>php-fpm -t</code>, preserve <code>date.timezone</code>.</li>
<li><strong>Tune</strong> with the same tuner as install, then repoint Angie from a TCP <code>127.0.0.1:9000</code> upstream to the new Unix socket if needed.</li>
<li><strong>Verify</strong> CLI version, units, every pool socket, that OPcache really loads, and that Angie has no leftover TCP handler. A Markdown report with rollback commands lands in <code>/var/log/setup-php-upgrade-&lt;timestamp&gt;.md</code>. If the tuned FPM does not start, the old version is rolled back.</li>
</ol>
<p>The resulting files are byte-identical to a fresh <code>--basic … --php ver=X.Y</code> install, and a following <code>--optimize</code> changes nothing.</p>
<h2 id="maintenance" class="heading-anchor">Maintenance<a class="anchor" href="#maintenance" aria-label="Link to section: Maintenance">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Command</th>
					<th>Behavior</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>--diagnostics</code></td>
					<td>one mode-600 <code>diagnostics.log</code>: hardware, network, sysctls, units, per-service config and runtime stats, slow/error logs, ownership, UFW, SSH, cron, package state. Read-only, credentials redacted</td>
			</tr>
			<tr>
					<td><code>--restart-all [--dry-run]</code></td>
					<td>repairs <code>/var/www</code> log ownership, stops Angie and active PHP-FPM, restarts Valkey/Redis, Elasticsearch (waits for HTTP) and MariaDB (waits for <code>SELECT 1</code>), then starts PHP-FPM and Angie. Only units that were active are touched</td>
			</tr>
			<tr>
					<td><code>--purge [TARGET...]</code></td>
					<td>stops and disables the selected services and removes managed cron entries</td>
			</tr>
	</tbody>
</table>
<p><code>--purge</code> targets are <code>all</code> (default), <code>basic</code>, <code>angie</code>, <code>php</code>, <code>mariadb</code>, <code>valkey</code>, <code>elastic</code>, <code>others</code>. Nothing is uninstalled or deleted: no package, no data, no log. <code>basic</code> restores the recorded hostname line, timezone, DNS, every sysctl the profile wrote, limits, the pre-install CPU governor, the unattended-upgrades state and UFW state, while leaving SSH rules and <code>/swapfile</code> alone.</p>
<p>That is the whole point of the recorded state in <code>/var/lib/setup.sh</code>: restore means <em>restore what was there</em>, not <em>assume the default</em>.</p>
<h2 id="tuning-pins-and-environment-overrides" class="heading-anchor">Tuning pins and environment overrides<a class="anchor" href="#tuning-pins-and-environment-overrides" aria-label="Link to section: Tuning pins and environment overrides">#</a></h2>
<p>Every automatic value has an override, and the overrides are scoped:</p>
<table>
	<thead>
			<tr>
					<th>Example</th>
					<th>Scope</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>SETUP_PHP_WORKERS_PER_CPU=1.5</code></td>
					<td>install or one run; <code>--optimize</code> ignores it</td>
			</tr>
			<tr>
					<td><code>SETUP_MARIADB_IO_CAPACITY=&quot;4000 8000&quot;</code></td>
					<td>install or one run; <code>--optimize</code> ignores it</td>
			</tr>
			<tr>
					<td><code>SETUP_BROTLI_LEVEL=6</code></td>
					<td>dynamic Brotli level</td>
			</tr>
			<tr>
					<td><code>SETUP_PRECOMPRESS_ASSETS=1</code></td>
					<td>pre-compress XenForo/WordPress assets and refresh from cron</td>
			</tr>
			<tr>
					<td><code>SETUP_PHP_PAGE_GZIP=0</code></td>
					<td>stop PHP gzipping WordPress/Chevereto pages into the cache</td>
			</tr>
			<tr>
					<td><code>SETUP_WP_GUEST_CACHE=0</code></td>
					<td>leave WordPress vhosts uncached instead of adding the include</td>
			</tr>
			<tr>
					<td><code>SETUP_UFW_SSH_LIMIT=0</code></td>
					<td>skip <code>ufw limit</code> on SSH, for an automation host</td>
			</tr>
	</tbody>
</table>
<p>The distinction matters: values recorded in <code>/etc/default/setup-tuning</code> persist across <code>--optimize</code>, while tuning pins made for a single run are cleared so the next run returns to the profile. Hand-editing the generated files does neither — the next <code>--optimize</code> will quietly correct you.</p>
<h2 id="testing" class="heading-anchor">Testing<a class="anchor" href="#testing" aria-label="Link to section: Testing">#</a></h2>
<p>The repository tests the claims, not just the code:</p>
<ul>
<li><code>tests/test-tuning.sh</code> (no root) covers the tuning helpers, memory plan, config repairs and rollback.</li>
<li><code>tests/test-dry-run-matrix.sh</code> runs every flag, app type, purge mode and representative invalid input through <code>--dry-run</code>.</li>
<li>CI runs both plus <code>shellcheck</code>.</li>
<li><code>tests/deploy-audit/</code> captures a host manifest or the managed config before and after, which is how install/<code>--optimize</code> parity is checked.</li>
<li><code>tests/stress-site/</code> deploys a synthetic full stack and drives it with local and remote load harnesses; <code>tests/bench-php-matrix/</code> holds the XenForo/PHP matrix and its reports.</li>
</ul>
<h2 id="files-and-state" class="heading-anchor">Files and state<a class="anchor" href="#files-and-state" aria-label="Link to section: Files and state">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Path</th>
					<th>Purpose</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>/run/setup.sh.lock</code></td>
					<td>run lock</td>
			</tr>
			<tr>
					<td><code>/var/lib/setup.sh/</code></td>
					<td>originals for <code>--purge basic</code>, package-origin markers, PHP upgrade snapshots</td>
			</tr>
			<tr>
					<td><code>/etc/default/setup-tuning</code></td>
					<td>host facts and feature choices kept across runs</td>
			</tr>
			<tr>
					<td><code>/etc/angie/</code></td>
					<td>Angie tree, vhosts, certificates, managed maps</td>
			</tr>
			<tr>
					<td><code>/etc/php/&lt;ver&gt;/fpm/…</code></td>
					<td><code>zz-setup-optimize.ini</code>, <code>custom_dan.ini</code>, <code>pool.d/www.conf</code></td>
			</tr>
			<tr>
					<td><code>/etc/mysql/mariadb.conf.d/</code></td>
					<td><code>50-server.cnf</code> base block, <code>99-setup-optimize.cnf</code> profile</td>
			</tr>
			<tr>
					<td><code>/etc/valkey/valkey.conf</code>, <code>/run/valkey/valkey.sock</code></td>
					<td>cache config and socket</td>
			</tr>
			<tr>
					<td><code>/etc/elasticsearch/…</code></td>
					<td>managed block and JVM heap file</td>
			</tr>
			<tr>
					<td><code>/var/www/logs/&lt;service&gt;/</code></td>
					<td>one rotated log tree for every service</td>
			</tr>
			<tr>
					<td><code>/var/log/setup-optimize-*.md</code>, <code>diagnostics.log</code>, <code>setup_*.log</code></td>
					<td>reports and run logs</td>
			</tr>
	</tbody>
</table>
<p>Credentials are never stored in the repository. The MariaDB password is written only to <code>/etc/mysqlbkup.cnf</code> on the target host.</p>
<h2 id="adopting-it-on-a-host-you-already-have" class="heading-anchor">Adopting it on a host you already have<a class="anchor" href="#adopting-it-on-a-host-you-already-have" aria-label="Link to section: Adopting it on a host you already have">#</a></h2>
<p>You do not need a fresh machine:</p>
<ol>
<li><code>--diagnostics</code> and read the drift section.</li>
<li><code>--optimize --dry-run</code> and check the plan against what you expect.</li>
<li><code>--optimize</code> in a window, then <code>--diagnostics</code> again.</li>
<li>Keep the run log with the change ticket.</li>
</ol>
<p>If a value is wrong for your workload, override it through the documented variables and keep the override recorded, rather than editing generated files that the next run will rewrite.</p>
<h2 id="what-it-does-not-do" class="heading-anchor">What it does not do<a class="anchor" href="#what-it-does-not-do" aria-label="Link to section: What it does not do">#</a></h2>
<ul>
<li>It is <strong>not</strong> a configuration-management system: no agent, no inventory, no central state. The unit of truth is the repository plus <code>/var/lib/setup.sh</code> on the host.</li>
<li>It does <strong>not</strong> alter application schemas: no <code>ALTER TABLE</code>, no index creation, no data change on a forum or CMS database. The README documents measured fixes that are deliberately left to the operator, such as a covering index for the XenForo Media Gallery count query.</li>
<li>It does <strong>not</strong> replace monitoring. A host tuned correctly in March can be wrong in June because someone edited one file; <code>--diagnostics</code> finds that when you run it, and a periodic run is what turns it into a policy.</li>
</ul>
<p>Within those limits, the design goal is simple: any run, on any supported host, leaves a state you can describe, repeat and undo.</p>
]]></content:encoded></item></channel></rss>