Docs cipi.yml Web panel API MCP Guides Compare GitHub Telegram channel
  1. Home
  2. Guides
  3. A Laravel API with a Next.js or Nuxt front end on one server
Laravel

A Laravel API with a Next.js or Nuxt front end on one server

Run a Laravel API and a server-rendered Next.js or Nuxt front end side by side, each with its own domain, zero-downtime deploys and HTTPS, plus Sanctum for authentication.

By Updated 2 min read

Two apps, one server: api.acme.app (Laravel) and acme.app (Next.js or Nuxt in SSR mode). Both deploy from Git with zero downtime; the Node app restarts blue/green.

  • acme.appNode app, SSR, blue/green restarts
  • api.acme.appLaravel app, FPM or Octane
  • Serverone Cipi install

Key ideas, in plain words#

TermMeaning
APIThe Laravel app answers JSON, no HTML
SSRServer-side rendering: Next.js or Nuxt runs as a Node process that builds HTML per request
SanctumLaravel's auth for SPAs (cookies) and mobile apps (tokens)
CORSBrowser rules for calling an API on another domain

1. The API#

bash
sudo cipi app create --user=api --domain=api.acme.app \
    --repository=git@github.com:acme/api.git --php=8.6
sudo cipi deploy api && sudo cipi ssl install api

For cookie-based auth from the front end, configure Sanctum: SANCTUM_STATEFUL_DOMAINS=acme.app, SESSION_DOMAIN=.acme.app, and CORS for https://acme.app:

bash
sudo cipi app env api --set=SANCTUM_STATEFUL_DOMAINS=acme.app
sudo cipi app env api --set=SESSION_DOMAIN=.acme.app

2. The front end#

bash
sudo cipi app create --user=web --domain=acme.app \
    --repository=git@github.com:acme/web.git --node=ssr --framework=next --node-version=24
sudo cipi deploy web && sudo cipi ssl install web

Use --framework=nuxt for Nuxt. Each deploy installs from your lockfile, builds, starts the new process, checks the health path and only then switches traffic.

ModeFor
ssrNext.js, Nuxt, SvelteKit, Remix, Astro SSR
staticPre-rendered sites (Astro, nuxt generate)
spaVite single-page apps

3. Point the front end at the API#

Build-time variables go in the Node app's shared/.env, read at build:

bash
sudo cipi app env web --set=NEXT_PUBLIC_API_URL=https://api.acme.app
sudo cipi deploy web

4. Keep both in their repositories#

Each repository can carry its own cipi.yml: workers, schedule and health for the API, node: settings for the front end. Examples in cipi.yml recipes.

Troubleshooting#

ProblemFix
CORS error in the browserAdd the front end's origin in config/cors.php, supports_credentials true for cookies
419 CSRF on loginCall /sanctum/csrf-cookie first; check SANCTUM_STATEFUL_DOMAINS and SESSION_DOMAIN
401 after loginCookie on the wrong domain: SESSION_DOMAIN=.acme.app
Front end calls the old API URLNEXT_PUBLIC_* is baked at build: redeploy the front end

Questions

Same domain or subdomains?

Subdomains (api.acme.app and acme.app) are simplest. Sanctum's cookie auth needs both on the same parent domain.

Can the front end be static instead?

Yes: --node=static --output=dist serves a built SPA from Nginx with no Node process.

Does the Node app get zero-downtime deploys too?

Yes. A new release is built and started, checked, then traffic switches.

What if a step fails?

Read the troubleshooting table above first. Then check the matching docs page, open a GitHub issue, or ask in the community. Most commands print the fix when they refuse something.

Do I need the web panel for this?

No. Every step works from the CLI. The optional web panel shows the same things in a browser.

Can I run these commands from my laptop?

Many of them, through cipi-cli and the API, with a scoped token. Otherwise ssh cipi@your-server and use sudo cipi ….

Will this affect other apps on the server?

No, unless the step says it's server-wide (installing a PHP version, firewall, Cloudflare tunnel). Each app has its own user, PHP pool, database and Valkey.

Try it on your own server

Free and open source. One command on a fresh Ubuntu 24.04 or 26.04 VPS.

wget -O - https://cipi.sh/setup.sh | bash
Read the quickstart