Until November 2026, haste.it, the website of the independent collective I founded in Campania, ran on a VPS: PHP, Nginx and SQLite. More than 200 PHP files (over 140 of them API endpoints), system cron jobs, uploaded images on the machine's disk, and a server that we had to keep patched ourselves.
The site does very different things at once: an online magazine, a petition with open data, a small catalogue with Stripe payments and an internal portal for the editorial team. The goal of the migration was simple to state: move everything to Cloudflare, with no server to administer, staying on the free plan, without losing a single feature or row of data.
This post is about the parts that were not obvious.
One Worker instead of 200 PHP files
Pages and API endpoints were rewritten in TypeScript inside a single Cloudflare Worker, organised in roughly 95 modules. One Worker means one deploy, one set of bindings and one place where routing, sessions and security headers live.
The interesting constraint is the free plan's daily request limit. The fix is to make sure the Worker runs only when it has to:
- CSS, JavaScript, fonts, images and every page that does not read the database are pre-rendered at build time and served by Workers Static Assets. Those requests never invoke the Worker.
- The Worker only handles dynamic pages and the API.
Normal browsing traffic therefore costs almost nothing against the limit.
SQLite to D1: the dump is not enough
D1 is SQLite underneath, so I expected sqlite3 .dump to be the whole story. It was not. I ended up writing a small converter that turns the SQLite file into SQL that D1 accepts, because of two problems.
1. FTS5 shadow tables. The magazine uses an FTS5 full-text index. An FTS5 virtual table is backed by internal "shadow" tables (<name>_data, <name>_idx, <name>_content, <name>_docsize, <name>_config), and a plain dump writes them out as ordinary tables. D1 rejects them on import. The converter skips them, and the index is rebuilt after the import from the real content tables:
-- after the import, repopulate the full-text index
INSERT INTO articles_fts(articles_fts) VALUES ('rebuild');
(The table name above is illustrative; the 'rebuild' command is standard FTS5.)
2. ID counters. Tables declared with AUTOINCREMENT keep their counter in sqlite_sequence. If the counters are not carried over, new rows can be given identifiers that were already used and deleted, which breaks anything that kept a reference to the old ID. The converter writes the counters back explicitly after the data.
Lesson: treat "SQLite-compatible" as "compatible for your queries", not "compatible for your file".
KV instead of R2 for images
R2 is the natural home for files uploaded by the editorial team, but enabling it requires a payment card even on the free tier. Workers KV does not. For our volume (editorial images, not user-generated media at scale) KV is enough, so uploads live in KV and are served by the Worker.
Cron without a server
The old crontab became two cron triggers on the same Worker:
- every 30 minutes, sync the news feed shown on the site;
- every night, delete expired sessions and rate-limit entries.
Same code base, same bindings, no extra service.
One address only
A Worker is reachable by default on a *.workers.dev subdomain, and preview deployments get their own URLs. Both were disabled, so the site exists only on haste.it and search engines never see duplicate copies:
// wrangler.jsonc (excerpt)
{
"workers_dev": false,
"preview_urls": false
}
Tests and headers
The Worker has automated tests with Vitest (security, input validation, database access) plus the TypeScript type check. The build minifies CSS and JavaScript and versions them with a content hash, so browsers can cache them for a long time without ever serving a stale file.
Every response carries HSTS, a Content-Security-Policy that allows scripts through a nonce generated per request, frame-ancestors to block embedding and a strict Referrer-Policy. All of it is visible to anyone who inspects the headers.
What I would tell myself before starting
- Check what the free plan requires, not only what it allows: R2's card requirement changed the storage design.
- Move static output out of the Worker first; it changes how much headroom you have for everything else.
- Write the database converter early and run it repeatedly against a copy of production data. The FTS5 and counter issues only show up with real data.
Once the migration was complete, the PHP code and the VPS configuration were removed from the repository.
I wrote a longer case study (in Italian) with the architecture and the status page that monitors the site: HASTE Collective, technical case study.
I'm Vincenzo Allocca, a software developer and Computer Engineering student in Naples. More projects on vincenzoallocca.dev.
Top comments (0)