A written deployment guide is a plan. A server built from it is only trustworthy if you record where reality differed from the plan, and if you have proved that rollback and restore work. That is the thesis of this case study: a methodical setup, with a labelled log, a tested rollback and a tested restore, is what makes a self-hosted Laravel server something I can rely on.

The problem

I set up a single virtual server for a self-hosted Laravel application by following a written guide. I logged every problem, extra step and difference from it.

Each entry carries one label. DEVIATION means I did something other than the guide says. EXTRA is a step the guide doesn't have. GUIDE BUG means the guide is wrong as written. TODO means it needs something only I can do, such as Cloudflare, GitHub or secrets. The log numbers its entries P1 to P21, and each records what I found, what I changed and what the guide needs to say instead.

The guide's earlier steps had already run, so before step 2 I checked what they left behind. SSH password authentication was still on. Swappiness was 60, not 10. The release folders had looser permissions than the guide specifies. The deploy user's SSH key lacked the restrict prefix. I fixed all four.

What I did

Verify the effective value, not the symptom

The SSH hardening file was named so it sorted after the cloud image's own file. sshd uses the first value it reads, so the guide's setting had no effect. Root login was refused anyway because of a separate setting, and that hid the problem. I renamed the file so it sorts first. Then I checked the effective value with sshd -T, not by watching a login get refused.

I applied the same rule to the web tier, and I tested it from outside as well as inside:

  • A direct connection to the origin timed out at the firewall.
  • An unknown host got a rejected handshake or a 444.
  • Through Cloudflare, the origin returned 403 until Authenticated Origin Pulls was turned on. I polled for about 2 minutes before concluding it was not active. After I enabled it, the log showed a verified client certificate.
  • The minimum TLS version was not set at the edge. I proved that by completing a TLS 1.1 handshake. After the fix, TLS 1.0 and 1.1 were refused.
  • HSTS was checked on the apex, on www and on the health endpoint.

Decisions, with what I ruled out

The server ran an interim Ubuntu release, not the LTS the guide assumed. The third-party PHP repository the guide uses had no packages for it. I ruled out running packages built for another release. I used Ubuntu's own PHP 8.5 instead, and checked the changelog for the security patches rather than comparing the upstream version number. The guide's install line also named an opcache package that does not exist for 8.5, because OPcache is built in. Because the release is supported for a limited time, I must upgrade or rebuild on an LTS before support ends.

Three more guide bugs turned up. MariaDB's config directory differed from the guide's path. Nginx already set server_tokens, so the guide's hardening file failed nginx -t. The guide included fastcgi_params after its own DOCUMENT_ROOT line, so the wrong value won. I fixed each one and wrote down the guide change.

The first deploy ran without an approval step. The repository is private on a free GitHub plan, which does not offer required reviewers, so I could not add that gate. I kept auto-deploy on every merge to main, with CI required to pass first. The consequence is that any merge deploys, including dependency bot PRs. I review those before merging.

What the health check missed

After the first deploy the site and health check were green, but the OAuth/MCP endpoint returned 500. The Passport keys had not been generated. The health check cannot catch that. I generated the keys and added "an unauthenticated request returns 401" to the go-live checks.

My own mistakes

A command I ran to redact a secret printed part of a generated database password into my session output. I logged it as a disclosure and recommended rotating the password. I also logged the temporary passwordless sudo I needed when it was granted and removed it at the end, then checked that all services were active, password SSH and root SSH login were off, and swappiness was 10.

The result

The first deploy ran 29 migrations after a pre-migration database dump, warmed the caches, and passed both a local and a through-Cloudflare smoke test.

Restore. A nightly job runs at 03:30 and writes a database dump and a storage archive, both readable by root only. I loaded the nightly dump into a scratch database. It had 27 tables and 1 user, the same as live. Then I dropped it.

Rollback. I deployed a new release, ran the rollback script to switch to the previous release, then ran it again to switch forward. During each switch I sent 30 requests to the health endpoint, and all 30 returned 200 both times, so there was no downtime. After each switch the home page, health endpoint and admin login returned 200 and the queue worker restarted cleanly.

A closure dispatched from tinker failed in the queue worker. That was a test artifact; I now test the queue with a real job class.

I did not end by calling the server finished. The open list is:

  • Mail domain verification.
  • An off-server backup copy. The server cannot make that itself, so it is on my to-do list.
  • An uptime monitor.
  • Cleanup of temporary files.
  • Dependency PR review.
  • The guide updates.