Jamstack (JavaScript, APIs, Markup) is an architecture pattern, not a technology stack. The core idea is simple: pre-render as much as possible into static HTML, serve it from a CDN, and use APIs for dynamic functionality. PHP fits naturally as the API layer in this architecture.
This site—phpeveryday.com—is itself a static site built with Hexo (a Node.js generator) and deployed to Cloudflare Pages. The content is authored in Markdown, built into static HTML at deploy time, and served globally from Cloudflare’s edge network. No PHP server runs in production. This approach works for content-heavy sites where pages rarely change.
But many applications need dynamic data: user authentication, form submissions, search, e-commerce. This is where PHP enters the Jamstack architecture as the API backend.
How PHP fits in Jamstack
1 | ┌──────────────┐ Build time ┌──────────────┐ |
PHP provides the data layer. The static frontend fetches data at build time (for pre-rendered pages) and at runtime (for dynamic interactions).
PHP as a headless CMS API
WordPress REST API
WordPress is the most common PHP headless CMS:
1 | // WordPress already has a REST API at /wp-json/wp/v2/ |
Custom Laravel API
1 | // routes/api.php |
Static frontend consuming PHP API
Next.js with PHP backend
1 | // Next.js: pages/articles/[slug].js |
Astro with PHP backend
1 | --- |
Nuxt with PHP backend
1 | <!-- pages/articles/[slug].vue --> |
Deploy webhooks: rebuilding on content change
When content changes in the PHP CMS, the static site needs to rebuild. Deploy webhooks automate this:
1 | // In WordPress: trigger rebuild when a post is published |
This is the same pattern this site uses: a daily Cloudflare Pages deploy hook rebuilds the site, and future-dated posts become visible when their publish date passes.
Handling dynamic functionality
Static sites need APIs for anything dynamic. PHP handles these well:
Search
1 | // PHP API: full-text search endpoint |
1 | // Frontend: search with debouncing |
Forms
1 | // PHP API: contact form endpoint |
Authentication
1 | // PHP API: token-based auth for Jamstack frontend |
Architecture patterns
Pattern 1: Static with PHP API (this site’s pattern)
- Content authored in Markdown/CMS
- Static site generator builds HTML at deploy time
- PHP API handles dynamic features (if any)
- Deployed to CDN (Cloudflare Pages, Vercel, Netlify)
Best for: blogs, documentation, marketing sites.
Pattern 2: PHP renders initial HTML, JavaScript hydrates
- PHP renders the first page load (fast TTFB, good SEO)
- JavaScript framework hydrates interactive components
- Subsequent navigation is client-side
1 | // Laravel with Inertia.js |
Best for: applications that need both SEO and interactivity.
Pattern 3: Full API separation
- PHP API is completely separate from the frontend
- Frontend is a standalone SPA or SSR application
- Communication is entirely through REST/GraphQL APIs
Best for: applications with multiple frontends (web, mobile, third-party).
Common mistakes
Over-decoupling simple sites: A WordPress blog does not need a React frontend. Server-rendered WordPress with good caching serves most content sites better than a Jamstack architecture with more moving parts.
Ignoring build times: A 10,000-page site with full rebuilds on every change can take 15+ minutes. Plan for incremental builds or on-demand revalidation.
Forgetting CORS: The static frontend and PHP API are on different domains. PHP must return proper Access-Control-Allow-Origin headers.
Not caching API responses: The static frontend fetches from the PHP API at build time. If the API is slow, builds are slow. Cache API responses aggressively.
FAQ
Is Jamstack replacing traditional PHP sites?
For content sites, partially. For applications with authentication, forms, and real-time features, traditional server-rendered PHP is often simpler. Jamstack adds architectural complexity that only pays off at scale or when CDN performance is critical.
Can I use PHP as both the API and the static site generator?
Yes. Tools like Jigsaw (Laravel-based) and Sculpin generate static sites from PHP. However, the JavaScript ecosystem (Next.js, Astro, Nuxt) has more mature static generation tooling.
What about SEO?
Static HTML is ideal for SEO—search engines get fully rendered content immediately. If using client-side rendering, ensure critical content is in the initial HTML response.
Next steps
If your current PHP site is content-heavy and could benefit from CDN-edge delivery, start by extracting the content into an API endpoint and building a static prototype with Astro or Next.js. Compare the performance and developer experience before committing to the architecture change.
For the API backend, the REST API guide and the GraphQL guide cover how to build the PHP API layer that powers a Jamstack frontend. The headless WordPress guide covers using WordPress specifically as a headless CMS.