Does Laravel Work With Cloudflare Pages?

Partially CompatibleLast verified: 2026-02-26

Laravel can be deployed to Cloudflare Pages, but only as a static site generator or API—full server-side rendering isn't natively supported.

Quick Facts

Compatibility
partial
Setup Difficulty
Moderate
Official Integration
No — community maintained
Confidence
medium
Minimum Versions
Laravel: 9.0

How Laravel Works With Cloudflare Pages

Laravel is a server-side PHP framework designed for traditional application servers, while Cloudflare Pages is a JAMstack platform optimized for static sites and serverless functions. The primary incompatibility stems from Laravel's reliance on PHP execution and server state, neither of which Cloudflare Pages natively supports. However, you have two viable integration paths: (1) Use Laravel as a static site generator via tools like Splade or Inertia for pre-rendering pages, then deploy the build output to Pages, or (2) Deploy your Laravel API separately to Cloudflare Workers or another PHP host, and serve a decoupled frontend (Vue/React) through Pages. The second approach is more common and maintains Laravel's backend robustness while leveraging Pages' global CDN for frontend delivery. You'll sacrifice some Laravel conveniences like server-side sessions and CSRF middleware, requiring token-based auth instead. Build times increase since you're pre-rendering or building a separate frontend application.

Best Use Cases

Headless CMS setup where Laravel powers the API and Pages serves a static frontend consuming that API
Blog or documentation site using Laravel's blade templates pre-rendered to static HTML via generators like Jigsaw
JAMstack applications with Laravel backend on Workers and Pages frontend for global distribution
Decoupled applications where Laravel handles complex business logic while Pages serves optimized static assets and API requests

Deploy Laravel API to Workers + Frontend to Pages

bash
composer create-project laravel/laravel api-app
bash
# wrangler.toml (for Laravel API on Workers)
name = "laravel-api"
main = "public/index.php"
compatibility_date = "2024-01-01"

[[env.production.routes]]
pattern = "api.example.com/*"
zone_name = "example.com"

# Build script for Pages frontend
#!/bin/bash
npm install
npm run build

# pages.json (Pages config)
{
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "envVars": {
    "VITE_API_URL": "https://api.example.com"
  }
}

# Frontend .env.production
VITE_API_URL=https://api.example.com

# Fetch from API in frontend
const response = await fetch(
  `${import.meta.env.VITE_API_URL}/api/posts`
);

Known Issues & Gotchas

critical

Laravel's server-side rendering and session management don't work on Cloudflare Pages

Fix: Use token-based authentication (JWT), pre-render pages as static HTML, or move to a serverless PHP runtime like Workers

warning

Build times can be lengthy if pre-rendering large Laravel applications with many routes

Fix: Use selective pre-rendering, implement on-demand ISR strategies, or split into API + frontend architecture

warning

Laravel's `.env` secrets can accidentally be exposed in static builds

Fix: Never commit secrets, use environment variables in your build process, and validate before deploying

critical

Database connections and server-side dependencies aren't available in the Pages environment

Fix: Query databases via API endpoints hosted elsewhere, or use Cloudflare's D1 database with Workers as an intermediary

Alternatives

  • Next.js deployed to Vercel—native Node.js support with database integration and API routes
  • Statamic or Craft CMS with headless API—Laravel-like PHP experience with built-in JAMstack support
  • Astro + Express/Laravel backend—Astro handles static generation while Express runs separately for dynamic content

Resources

Related Compatibility Guides

Explore more compatibility guides