Guide · Websites and forms
How to leave WordPress: a fast, secure website with Astro, Cloudflare, an API and PostgreSQL on AWS
A guide and free template to replace WordPress with a static Astro website behind Cloudflare, with an API protected by AWS WAF, CORS locked to your domain and a private PostgreSQL database on AWS.
- Updated
- Oct 22, 2026
- Reading time
- 14 min
- Tools
- 7
Short answer: replace WordPress with a static Astro website, served from Cloudflare with its WAF in front, and move the only dynamic part (the forms) to a small API with PostgreSQL on AWS: a database with no public IP, secrets in Secrets Manager, AWS WAF in front and CORS locked to your domain. All of it in Git. The result is a website that loads in milliseconds, has no PHP to patch and whose only entry point is watched by two firewalls. The full template, with tests, is on our GitHub (code and README in Spanish).
Why leave WordPress now
On 21 October 2026 the patch for PHP2Shell was released: two critical flaws that allow someone to take over a server without logging in. There are patches only for PHP 8.2 onwards. We estimate that some 115,500 websites from Spain’s Kit Digital programme are still on PHP 8.1 or earlier.
The problem isn’t just this flaw. A WordPress website is a program that runs on every visit: PHP, the core, the theme and every plugin. All of that has to be kept up to date, always, and almost nobody does it once the maintenance contract ends. Most small-business websites are five pages and a form: they don’t need a server running code to show some text.
The architecture
It’s the same idea this website, yeswelab.com, uses (Astro, its own API with PostgreSQL and everything in Git), reinforced with Cloudflare in front of the frontend and AWS behind:
| Layer | Component | What protects it |
|---|---|---|
| Entry | Cloudflare (DNS, CDN and certificate) | Managed WAF, custom rules, rate limiting, Bot Fight Mode, DNSSEC |
| Frontend | Static Astro website | Runs no code: just files. Strict CSP, HSTS, no iframes |
| Forms | Cloudflare Turnstile | Free, invisible captcha; the token is validated in the API |
| API | FastAPI on AWS ECS Express Mode | AWS WAF, locked CORS, origin check, per-IP limit, strict validation |
| Data | PostgreSQL 18 on Amazon RDS | No public IP, encrypted, 7-day backups, accepts only the API, least-privilege user |
| Code | Git (GitHub) | Every change is recorded; secrets kept out of the repository |
If someone gets into the API, the database user can only insert and count messages: it can’t read them, delete them or create tables. The template’s tests check this.
Step 1: the template
git clone https://github.com/magranero/yeswelab-laboratorio
cd yeswelab-laboratorio/web-segura-sin-wordpress-astro-cloudflare-aws
docker compose up -d --build # PostgreSQL and the API locally
cd api && uv run pytest # 17 tests
cd ../web && npm install && npm run dev
It includes a sample website with a contact form, the API, the database schema, the Cloudflare configuration and the AWS commands. We tested it locally with PostgreSQL 18: the form submits, the API stores, and requests from another website get a 403.
Step 2: moving WordPress content to Astro
- Export the content: in WordPress, Tools → Export → All content. You download an XML file with pages and posts.
- Convert it to Markdown: each page becomes a
.mdfile insrc/content/. With Claude it’s quick: give it the XML and the template and ask for the pages in Astro, keeping titles, descriptions and URLs. - Keep the URLs or, if they change, create 301 redirects in
public/_redirectsonly for those with traffic in Search Console. That way you don’t lose your Google rankings. - Images: into
src/assets/, so Astro optimises them and sets their dimensions.
If the client needs to edit text, add a CMS that stores in Git, such as Decap CMS or Keystatic. They edit in a panel and every change republishes the static website.
Step 3: the frontend on Cloudflare, with the WAF set up properly
The website is published with npm run deploy on Cloudflare Workers with static assets: the files are served from Cloudflare’s network, with security in front. In the Cloudflare dashboard:
-
SSL/TLS: “Always Use HTTPS”, minimum TLS 1.2 and DNSSEC turned on.
-
Managed WAF: on the free plan, Cloudflare’s managed ruleset is already active.
-
Custom rules (5 on the free plan). Two that shut the door on almost all the noise:
# A static website only receives GET and HEAD (http.request.method ne "GET" and http.request.method ne "HEAD") # Anyone looking for a WordPress or a .env has no business here (http.request.uri.path contains "/wp-" or http.request.uri.path contains ".php" or http.request.uri.path contains "/.env" or http.request.uri.path contains "/.git") -
Rate limiting: the free plan allows 1 rule, counted per IP over 10-second periods. For example, more than 100 requests in 10 seconds → block.
-
Bot Fight Mode turned on.
-
Turnstile: create a widget for your domain. The site key goes in the website; the secret, only in the API.
And the security headers travel with the website itself, in public/_headers:
/*
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Content-Security-Policy: default-src 'self'; script-src 'self' https://challenges.cloudflare.com; frame-src https://challenges.cloudflare.com; connect-src 'self' https://api.tudominio.es; ...
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
The CSP only allows scripts from your domain and from Turnstile, and connections only to your API. For it to work, the template configures Astro never to inline scripts or styles.
Step 4: the API, with CORS locked to your website
The API does only one thing: receive the form, validate it, store it and notify you (via Telegram, if you want). Its defences, from the outside in:
app = FastAPI(docs_url=None, redoc_url=None, openapi_url=None) # no public map of the API
app.add_middleware(
CORSMiddleware,
allow_origins=["https://tudominio.es", "https://www.tudominio.es"], # never "*"
allow_methods=["POST"],
allow_headers=["Content-Type"],
)
- Locked CORS: only your domain can call it from a browser.
- Origin checked on the server: before the body is read, a POST that doesn’t come from your website gets a 403.
- Turnstile: each submission carries a token that the API validates with Cloudflare, and which must have been issued for your domain.
- Bot protection without friction: a hidden field that only bots fill in, and a minimum fill-in time. The bot gets an “OK” so it gets no clues, but nothing is stored.
- Per-IP limit: 5 submissions per hour. The IP is stored as a hash, never in plain text.
- Strict validation: each field with its type and maximum length.
CORS is not a firewall. Only browsers respect it. It stops another website from using your API from its visitors’ browsers, but a script can bypass it and set whatever
Originit likes. That’s why it never works alone: Turnstile, the per-IP limit and the WAF are what stop scripts.
Step 5: the API and PostgreSQL on AWS, protected
The template includes the commands in aws/README.md. What matters about each piece:
PostgreSQL on RDS, private. It’s created with --no-publicly-accessible (no public IP), --storage-encrypted, 7-day backups, deletion protection, automatic minor patches and the admin password generated and stored in Secrets Manager. Its security group only accepts port 5432 from the API tasks. And the connection requires TLS (sslmode=require).
Least-privilege user. The admin creates the table once. The API connects as app_web, which can only insert:
REVOKE ALL ON SCHEMA public FROM PUBLIC;
GRANT USAGE ON SCHEMA public TO app_web;
GRANT SELECT (id, creado, ip_hash), INSERT ON contactos TO app_web;
Secrets out of the code. The database URL, the Turnstile secret and the IP salt go into Secrets Manager. The container receives them as environment variables, and its role can only read those secrets.
The API on ECS Express Mode. App Runner stopped accepting new customers on 30 April 2026, and AWS recommends ECS Express Mode instead. With one command it creates the Fargate service, the HTTPS load balancer, scaling and logs. The image lives in ECR with vulnerability scanning on every push and runs without root.
AWS WAF in front of the load balancer, with five rules:
| Rule | What it stops |
|---|---|
| API routes only | Anything that isn’t /v1/… or /health: anyone looking for /wp-admin or /.env stays out |
| Per-IP limit | More than 100 requests in 5 minutes from the same IP |
| IPs with a bad reputation | Amazon’s list of IPs used by bots and attackers |
| Common attacks | AWS managed rules against the OWASP Top 10 |
| Known bad inputs | Patterns from known exploits |
We checked the AWS commands against the official documentation in October 2026, but we haven’t run them on a real account: review each step in the console.
Step 6: everything in Git
- One repository per website, with
mainprotected: changes go in via pull request. - Automatic deployment on merge: Cloudflare publishes the website and AWS the new API image.
- Never secrets in the repository:
.envin.gitignoreand the real secrets in Secrets Manager and in the Cloudflare dashboard. - Dependency alerts (Dependabot on GitHub) for Astro and the API libraries.
Pre-launch checklist
| Check | How |
|---|---|
| HTTPS enforced and HSTS | curl -sI https://tudominio.es shows Strict-Transport-Security |
| CSP with no errors | The browser console shows no blocks when submitting the form |
| CORS locked | An OPTIONS from another origin doesn’t return Access-Control-Allow-Origin |
| The API rejects other origins | A POST with Origin: https://otra-web.com returns 403 |
| The WAF filters | https://api…/wp-admin returns 403 |
| Private database | The RDS endpoint doesn’t respond from your home connection |
| Backups active | RDS → Automated backups: 7 days |
| No secrets in Git | git log -p contains no passwords or keys |
What it costs
- Cloudflare: the free plan covers the frontend, the managed WAF, the rules above and Turnstile.
- AWS: you pay for the load balancer, Fargate, RDS, logs and AWS WAF ($5 a month per ACL, $1 per rule and $0.60 per million requests). Work out your case with the AWS calculator and your region.
- The trick for agencies: the Express Mode load balancer is shared by up to 25 services, and one RDS instance can host one database per client. A single protected infrastructure for the whole portfolio.
If it’s a single website and AWS is overkill, the same API works on a VPS with Docker, which is how this website’s API runs. You lose AWS WAF, but not Cloudflare in front of the frontend or the API’s own defences.
Limitations
- It’s not for everything. A shop with thousands of products or a customer portal needs more than a form: the API grows, and so does what you have to maintain.
- We haven’t run the AWS commands on a real account. The API, the database, the website and their defences we did test locally, with 17 tests and a real submission from the browser.
- Security isn’t install-and-forget: update dependencies, review the WAF logs and test from time to time that backups can be restored.
Related
- PHP2Shell, PHP 7 and Spain’s Kit Digital: some 115,500 unpatched websites: why it’s worth getting off PHP.
- How to find out what technology a website uses and who owns it: inventory your portfolio before migrating.
- Building websites and forms with AI or no code
What we would do in the lab
If you have a portfolio of WordPress websites, we migrate one with you, measure load times, monthly cost and attack surface before and after, and leave you a process ready to repeat with the rest.
Want to know how much you’d gain by leaving WordPress? Commission the experiment.
Frequently asked questions
What can I use instead of WordPress?
For a company website with a few pages, a static site generator such as Astro: it produces plain HTML served from a CDN, with no PHP and no exposed database. The dynamic parts (forms, bookings) go to a small API with its own database.
Is a static website more secure than WordPress?
Yes, because it doesn't run code on the server when someone visits: there's no PHP, no plugins and no admin panel to attack. The attack surface is reduced to the API, which is small and sits behind a WAF.
What is CORS and is it enough to protect an API?
CORS is the rule that tells browsers which websites can call your API. Locking it to your domain stops another website from using it from its visitors' browsers, but it isn't enough: a script can call it anyway. That's why you also need to check the origin on the server, a captcha such as Turnstile, a per-IP limit and a WAF.
Is Cloudflare free?
The free plan includes DNS, CDN, a certificate, its WAF's managed ruleset, 5 custom rules, 1 rate-limiting rule and Turnstile. For a small business's static website it's usually enough.
How much does the AWS part cost?
It depends on the region and the traffic: you pay for the load balancer, Fargate, RDS, logs and AWS WAF ($5 a month per ACL, $1 per rule and $0.60 per million requests). For a single small business it's more expensive than shared hosting; for an agency it pays off because one load balancer serves up to 25 services and one database instance can host many clients' databases.
Can my client keep editing the website without knowing how to code?
Yes, with a CMS that stores changes in Git, such as Decap CMS or Keystatic: the client edits in a panel and every change republishes the static website. No PHP server to maintain.