Server-Side Rendering (SSR)
- Laravel Starter Kits
- Vite Plugin Setup
- Manual Setup
- Running the SSR Server
- Error Handling
- Configuring the SSR Request
- Disabling SSR
- Excluding Routes from SSR
- Client-Only Components
- Deployment
Server-side rendering pre-renders your JavaScript pages on the server, allowing your visitors to receive fully rendered HTML when they visit your application. Since fully rendered HTML is served by your application, it's also easier for search engines to index your site.
Server-side rendering uses Node.js to render your pages in a background process; therefore, Node must be available on your server for server-side rendering to function properly. Inertia's SSR server requires Node.js 22 or higher.
Laravel Starter Kits
If you are using Laravel Starter Kits, Inertia SSR is supported through a build command:
1npm run build:ssr1npm run build:ssr
Vite Plugin Setup
The recommended way to configure SSR is with the @inertiajs/vite plugin. This approach handles SSR configuration automatically, including development mode SSR without a separate Node.js server.
1. Install the Vite plugin
1npm install @inertiajs/vite1npm install @inertiajs/vite
2. Configure Vite
Add the Inertia plugin to your vite.config.js file. The plugin will automatically detect your SSR entry point.
1import inertia from '@inertiajs/vite'2import laravel from 'laravel-vite-plugin'3import { defineConfig } from 'vite'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 inertia(),12 ],13})1import inertia from '@inertiajs/vite'2import laravel from 'laravel-vite-plugin'3import { defineConfig } from 'vite'45export default defineConfig({6 plugins: [7 laravel({8 input: ['resources/js/app.js'],9 refresh: true,10 }),11 inertia(),12 ],13})
You may also configure SSR options explicitly.
1inertia({2 ssr: {3 entry: 'resources/js/ssr.js',4 port: 13714,5 host: '127.0.0.1',6 cluster: true,7 },8})1inertia({2 ssr: {3 entry: 'resources/js/ssr.js',4 port: 13714,5 host: '127.0.0.1',6 cluster: true,7 },8})
You may pass false to opt out of the plugin's automatic SSR handling, for example if you prefer to configure SSR manually or disable SSR entirely.
1inertia({2 ssr: false,3})1inertia({2 ssr: false,3})
3. Update your build script
Update the build script in your package.json to build both bundles.
1"scripts": {2 "dev": "vite",3 "build": "vite build" // [!code --]4 "build": "vite build && vite build --ssr" // [!code ++]5},1"scripts": {2 "dev": "vite",3 "build": "vite build" // [!code --]4 "build": "vite build && vite build --ssr" // [!code ++]5},
Development Mode
The Vite plugin handles SSR automatically during development. There is no need to build your SSR bundle or start a separate Node.js server. Simply run your Vite dev server as usual:
1npm run dev1npm run dev
The Vite plugin exposes a server endpoint that Laravel uses for rendering, complete with HMR support.
SSR is disabled by default, so enable it in your .env file first:
1INERTIA_SSR=true1INERTIA_SSR=true
Production
For production, build both bundles and start the SSR server.
1npm run build2php artisan inertia:start-ssr1npm run build2php artisan inertia:start-ssr
1npm run build:ssr2node bootstrap/ssr/app.js1npm run build:ssr2node bootstrap/ssr/app.js
Make sure INERTIA_SSR=true is set in your environment and that bootstrap/ssr/app.js is built before starting your application binary, because outside debug mode Laravel checks for the bundle once on startup.
Clustering
By default, the SSR server runs on a single thread. You may enable clustering to start multiple Node servers on the same port, with requests handled by each thread in a round-robin fashion.
1inertia({2 ssr: {3 cluster: true,4 },5})1inertia({2 ssr: {3 cluster: true,4 },5})
Host
By default, the SSR server binds to 0.0.0.0, making it accessible on all network interfaces. You may restrict it to a specific interface using the host option.
1inertia({2 ssr: {3 host: '127.0.0.1',4 },5})1inertia({2 ssr: {3 host: '127.0.0.1',4 },5})
Manual Setup
The Vite plugin reuses your app.js entry point for SSR by default, so no separate file is needed. Most customizations may be handled using the withApp callback.
For more control, such as providing a manual setup callback, you may create a separate resources/js/ssr.js entry point and update your app.js to use client-side hydration.
SSR Entry Point
1import { createInertiaApp } from '@inertiajs/vue3'2import createServer from '@inertiajs/vue3/server'3import { createSSRApp, h } from 'vue'4import { renderToString } from 'vue/server-renderer'56createServer(page =>7 createInertiaApp({8 page,9 render: renderToString,10 resolve: name => {11 const pages = import.meta.glob('./Pages/**/*.vue')12 return pages[`./Pages/${name}.vue`]()13 },14 setup({ App, props, plugin }) {15 return createSSRApp({16 render: () => h(App, props),17 }).use(plugin)18 },19 }),20)1import { createInertiaApp } from '@inertiajs/vue3'2import createServer from '@inertiajs/vue3/server'3import { createSSRApp, h } from 'vue'4import { renderToString } from 'vue/server-renderer'56createServer(page =>7 createInertiaApp({8 page,9 render: renderToString,10 resolve: name => {11 const pages = import.meta.glob('./Pages/**/*.vue')12 return pages[`./Pages/${name}.vue`]()13 },14 setup({ App, props, plugin }) {15 return createSSRApp({16 render: () => h(App, props),17 }).use(plugin)18 },19 }),20)
1import { createInertiaApp } from '@inertiajs/react'2import createServer from '@inertiajs/react/server'3import ReactDOMServer from 'react-dom/server'45createServer(page =>6 createInertiaApp({7 page,8 render: ReactDOMServer.renderToString,9 resolve: name => {10 const pages = import.meta.glob('./Pages/**/*.jsx')11 return pages[`./Pages/${name}.jsx`]()12 },13 setup: ({ App, props }) => <App {...props} />,14 }),15)1import { createInertiaApp } from '@inertiajs/react'2import createServer from '@inertiajs/react/server'3import ReactDOMServer from 'react-dom/server'45createServer(page =>6 createInertiaApp({7 page,8 render: ReactDOMServer.renderToString,9 resolve: name => {10 const pages = import.meta.glob('./Pages/**/*.jsx')11 return pages[`./Pages/${name}.jsx`]()12 },13 setup: ({ App, props }) => <App {...props} />,14 }),15)
1import { createInertiaApp } from '@inertiajs/svelte'2import createServer from '@inertiajs/svelte/server'3import { render } from 'svelte/server'45createServer(page =>6 createInertiaApp({7 page,8 resolve: name => {9 const pages = import.meta.glob('./Pages/**/*.svelte')10 return pages[`./Pages/${name}.svelte`]()11 },12 setup({ App, props }) {13 return render(App, { props })14 },15 }),16)1import { createInertiaApp } from '@inertiajs/svelte'2import createServer from '@inertiajs/svelte/server'3import { render } from 'svelte/server'45createServer(page =>6 createInertiaApp({7 page,8 resolve: name => {9 const pages = import.meta.glob('./Pages/**/*.svelte')10 return pages[`./Pages/${name}.svelte`]()11 },12 setup({ App, props }) {13 return render(App, { props })14 },15 }),16)
Be sure to add anything that's missing from your app.js file that makes sense to run in SSR mode, such as plugins or custom mixins.
Client-Side Hydration
You should also update your app.js to use hydration instead of normal rendering. This allows VueReactSvelte to pick up the server-rendered HTML and make it interactive without re-rendering it.
1import { createApp, h } from 'vue' // [!code --]2import { createSSRApp, h } from 'vue' // [!code ++]3import { createInertiaApp } from '@inertiajs/vue3'45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.vue')8 return pages[`./Pages/${name}.vue`]()9 },10 setup({ el, App, props, plugin }) {11 createApp({ render: () => h(App, props) }) // [!code --]12 createSSRApp({ render: () => h(App, props) }) // [!code ++]13 .use(plugin)14 .mount(el)15 },16})1import { createApp, h } from 'vue' // [!code --]2import { createSSRApp, h } from 'vue' // [!code ++]3import { createInertiaApp } from '@inertiajs/vue3'45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.vue')8 return pages[`./Pages/${name}.vue`]()9 },10 setup({ el, App, props, plugin }) {11 createApp({ render: () => h(App, props) }) // [!code --]12 createSSRApp({ render: () => h(App, props) }) // [!code ++]13 .use(plugin)14 .mount(el)15 },16})
1import { createInertiaApp } from '@inertiajs/react'2import { createRoot } from 'react-dom/client' // [!code --]3import { hydrateRoot } from 'react-dom/client' // [!code ++]45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.jsx')8 return pages[`./Pages/${name}.jsx`]()9 },10 setup({ el, App, props }) {11 createRoot(el).render(<App {...props} />) // [!code --]12 hydrateRoot(el, <App {...props} />) // [!code ++]13 },14})1import { createInertiaApp } from '@inertiajs/react'2import { createRoot } from 'react-dom/client' // [!code --]3import { hydrateRoot } from 'react-dom/client' // [!code ++]45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.jsx')8 return pages[`./Pages/${name}.jsx`]()9 },10 setup({ el, App, props }) {11 createRoot(el).render(<App {...props} />) // [!code --]12 hydrateRoot(el, <App {...props} />) // [!code ++]13 },14})
1import { createInertiaApp } from '@inertiajs/svelte'2import { mount } from 'svelte' // [!code --]3import { hydrate, mount } from 'svelte' // [!code ++]45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.svelte')8 return pages[`./Pages/${name}.svelte`]()9 },10 setup({ el, App, props }) {11 mount(App, { target: el, props }) // [!code --]12 if (el.dataset.serverRendered === 'true') { // [!code ++:5]13 hydrate(App, { target: el, props })14 } else {15 mount(App, { target: el, props })16 }17 },18})1import { createInertiaApp } from '@inertiajs/svelte'2import { mount } from 'svelte' // [!code --]3import { hydrate, mount } from 'svelte' // [!code ++]45createInertiaApp({6 resolve: name => {7 const pages = import.meta.glob('./Pages/**/*.svelte')8 return pages[`./Pages/${name}.svelte`]()9 },10 setup({ el, App, props }) {11 mount(App, { target: el, props }) // [!code --]12 if (el.dataset.serverRendered === 'true') { // [!code ++:5]13 hydrate(App, { target: el, props })14 } else {15 mount(App, { target: el, props })16 }17 },18})
Opting Out of the Vite Plugin
You may pass ssr: false to the Inertia plugin to disable its automatic SSR handling and manage the SSR build yourself. You should also add the ssr property to the Laravel Vite plugin configuration so it knows about your entry point.
1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.js'],5 ssr: 'resources/js/ssr.js', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.js'],5 ssr: 'resources/js/ssr.js', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})
1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.jsx'],5 ssr: 'resources/js/ssr.jsx', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.jsx'],5 ssr: 'resources/js/ssr.jsx', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})
1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.js'],5 ssr: 'resources/js/ssr.js', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})1export default defineConfig({2 plugins: [3 laravel({4 input: ['resources/js/app.js'],5 ssr: 'resources/js/ssr.js', // [!code ++]6 refresh: true,7 }),8 inertia({9 ssr: false, // [!code ++]10 }),11 ],12})
Clustering
You may pass the cluster option to createServer to start multiple Node servers on the same port, with requests handled by each thread in a round-robin fashion.
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { cluster: true },6)
Host
By default, the SSR server binds to 0.0.0.0, making it accessible on all network interfaces. You may pass the host option to createServer to restrict it to a specific interface.
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)
1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)1createServer(page =>2 createInertiaApp({3 // ...4 }),5 { host: '127.0.0.1' },6)
Running the SSR Server
The SSR server is only required in production. During development, the Vite plugin handles SSR automatically.
Once you have built both your client-side and server-side bundles, you may start the SSR server.
1php artisan inertia:start-ssr1php artisan inertia:start-ssr
1node bootstrap/ssr/app.js1node bootstrap/ssr/app.js
The SSR server uses node as its runtime by default. You may change this by setting the runtime option in your config/inertia.php file. An absolute path to the runtime binary is also supported.
1'ssr' => [2 'runtime' => env('INERTIA_SSR_RUNTIME', 'node'),3],1'ssr' => [2 'runtime' => env('INERTIA_SSR_RUNTIME', 'node'),3],
The --runtime flag on the Artisan command overrides the configured value for a single invocation.
You may also invoke the SSR bundle with another JavaScript runtime, such as Bun.
1php artisan inertia:start-ssr --runtime=bun1php artisan inertia:start-ssr --runtime=bun
1bun bootstrap/ssr/app.js1bun bootstrap/ssr/app.js
You may also enable the ensure_runtime_exists option to verify the runtime binary exists before attempting to start the SSR server. The command will exit with an error if the binary cannot be found.
1'ssr' => [2 'ensure_runtime_exists' => (bool) env('INERTIA_SSR_ENSURE_RUNTIME_EXISTS', false),3],1'ssr' => [2 'ensure_runtime_exists' => (bool) env('INERTIA_SSR_ENSURE_RUNTIME_EXISTS', false),3],
With the server running, you should be able to access your app in the browser with server-side rendering enabled. In fact, you should be able to disable JavaScript entirely and still navigate around your application.
Error Handling
When SSR rendering fails, Inertia gracefully falls back to client-side rendering. The Vite plugin logs detailed error information to the console, including the component name, request URL, source location, and a tailored hint to help you resolve the issue.
Common SSR errors are automatically classified. Browser API errors (such as referencing window or document in server-rendered code) include guidance on moving the code to a lifecycle hook. Components that depend on browser APIs may also be wrapped in WhenMounted. Component resolution errors suggest checking file paths and casing.
Inertia also dispatches an SsrRenderFailed event on the server. You may listen for this event to log failures or send them to an error tracking service.
1use Illuminate\Support\Facades\Log;2use Inertia\Ssr\SsrRenderFailed;34Event::listen(SsrRenderFailed::class, function (SsrRenderFailed $event) {5 Log::warning('SSR failed', $event->toArray());6});1use Illuminate\Support\Facades\Log;2use Inertia\Ssr\SsrRenderFailed;34Event::listen(SsrRenderFailed::class, function (SsrRenderFailed $event) {5 Log::warning('SSR failed', $event->toArray());6});
SSR connection and render failures are logged via tracing before falling back to client-side rendering.
Throwing on Error
Since Inertia gracefully falls back to client-side rendering, SSR failures may go unnoticed. Your tests pass because the client-side render succeeds, but your users never receive server-rendered HTML. This is especially common in E2E tests with tools like Laravel Dusk or Pest Browser Testing.
You may set the throw_on_error option in your config/inertia.php file to throw an exception instead of falling back silently, allowing you to catch SSR issues early.
1'ssr' => [2 'throw_on_error' => (bool) env('INERTIA_SSR_THROW_ON_ERROR', false),3],1'ssr' => [2 'throw_on_error' => (bool) env('INERTIA_SSR_THROW_ON_ERROR', false),3],
This option is not recommended for production, as it will cause SSR failures to return an error response instead of falling back to client-side rendering.
You may set the environment variable in your phpunit.xml to enable this only during testing.
1<env name="INERTIA_SSR_THROW_ON_ERROR" value="true"/>1<env name="INERTIA_SSR_THROW_ON_ERROR" value="true"/>
Configuring the SSR Request
Laravel PHP Adapter v3.4.0+
The request to the SSR server uses Laravel's HTTP client defaults. You may set the timeout option in your config/inertia.php file so a slow or unresponsive SSR server doesn't delay your responses, as Inertia falls back to client-side rendering when the request fails.
1'ssr' => [2 'timeout' => env('INERTIA_SSR_TIMEOUT'),3],1'ssr' => [2 'timeout' => env('INERTIA_SSR_TIMEOUT'),3],
For more control, you may use the Inertia::configureSsrRequestUsing() method, typically from a service provider. The callback receives the PendingRequest before it is sent, so you may add retries, headers, or any other option supported by Laravel's HTTP client.
1use Illuminate\Http\Client\PendingRequest;2use Inertia\Inertia;34Inertia::configureSsrRequestUsing(function (PendingRequest $request) {5 $request->timeout(5)->retry(2, throw: false);6});1use Illuminate\Http\Client\PendingRequest;2use Inertia\Inertia;34Inertia::configureSsrRequestUsing(function (PendingRequest $request) {5 $request->timeout(5)->retry(2, throw: false);6});
When using retry(), pass throw: false so failed renders are still reported with the error details from the SSR server.
Both the timeout and the callback apply to the render request and the health check used by the inertia:check-ssr command.
Laravel Rust's built-in SSR gateway uses a 5-second timeout by default and falls back to client-side rendering when the request fails.
Disabling SSR
SSR has two layers: the Vite plugin serves SSR during development and builds the SSR bundle for production, while the Laravel adapter dispatches rendering requests to the SSR server. To fully disable SSR, you should disable both.
1inertia({2 ssr: false,3})1inertia({2 ssr: false,3})
1'ssr' => [2 'enabled' => false,3],1'ssr' => [2 'enabled' => false,3],
1INERTIA_SSR=false1INERTIA_SSR=false
You may also prevent the adapter from dispatching SSR requests programmatically using the Inertia::disableSsr() method. This is useful when you want to keep SSR in your build but disable it during tests or in specific environments.
1use Inertia\Inertia;23Inertia::disableSsr();1use Inertia\Inertia;23Inertia::disableSsr();
A boolean or closure may be provided to disable SSR conditionally.
1Inertia::disableSsr(app()->runningUnitTests());23Inertia::disableSsr(fn () => app()->runningUnitTests());1Inertia::disableSsr(app()->runningUnitTests());23Inertia::disableSsr(fn () => app()->runningUnitTests());
Excluding Routes from SSR
Sometimes you may wish to skip server-side rendering for certain routes while keeping SSR enabled for the rest of your application.
Per-Request
You may disable SSR for a single page or request. Set the inertia.ssr.enabled configuration value to false.Chain without_ssr() onto inertia::render().
1if (request()->is('admin/*')) {2 config(['inertia.ssr.enabled' => false]);3}1if (request()->is('admin/*')) {2 config(['inertia.ssr.enabled' => false]);3}
1use laravel::inertia::{self, Page};23pub async fn dashboard() -> Page {4 inertia::render("Admin/Dashboard", ()).without_ssr()5}1use laravel::inertia::{self, Page};23pub async fn dashboard() -> Page {4 inertia::render("Admin/Dashboard", ()).without_ssr()5}
Via Middleware
In Laravel PHP, you may use the $withoutSsr property on your Inertia middleware to disable SSR for specific route patterns.
1use Inertia\Middleware;23class HandleInertiaRequests extends Middleware4{5 /**6 * Defines the routes that should not use SSR.7 *8 * @var array<int, string>9 */10 protected $withoutSsr = [11 'admin/*',12 'dashboard',13 ];14}1use Inertia\Middleware;23class HandleInertiaRequests extends Middleware4{5 /**6 * Defines the routes that should not use SSR.7 *8 * @var array<int, string>9 */10 protected $withoutSsr = [11 'admin/*',12 'dashboard',13 ];14}
Via Facade
In Laravel PHP, you may also exclude specific routes using the Inertia::withoutSsr() method, typically called from a service provider.
1use Inertia\Inertia;23Inertia::withoutSsr(['admin/*', 'dashboard']);1use Inertia\Inertia;23Inertia::withoutSsr(['admin/*', 'dashboard']);
Client-Only Components
v3.8.0+
Sometimes, a component relies on browser APIs such as window or document and cannot be rendered on the server. Instead of disabling SSR for the entire page, you may wrap the component in WhenMounted, which renders its children only after mounting in the browser. The fallback is rendered on the server and during hydration instead.
1<script setup>2import { WhenMounted } from "@inertiajs/vue3";3import Chart from "@/Components/Chart.vue";4</script>56<template>7 <WhenMounted>8 <template #fallback>9 <div>Loading chart...</div>10 </template>1112 <Chart />13 </WhenMounted>14</template>1<script setup>2import { WhenMounted } from "@inertiajs/vue3";3import Chart from "@/Components/Chart.vue";4</script>56<template>7 <WhenMounted>8 <template #fallback>9 <div>Loading chart...</div>10 </template>1112 <Chart />13 </WhenMounted>14</template>
1import { WhenMounted } from "@inertiajs/react";2import Chart from "@/Components/Chart";34export default () => (5 <WhenMounted fallback={<div>Loading chart...</div>}>6 <Chart />7 </WhenMounted>8);1import { WhenMounted } from "@inertiajs/react";2import Chart from "@/Components/Chart";34export default () => (5 <WhenMounted fallback={<div>Loading chart...</div>}>6 <Chart />7 </WhenMounted>8);
1<script>2 import { WhenMounted } from "@inertiajs/svelte";3 import Chart from "@/Components/Chart.svelte";4</script>56<WhenMounted>7 {#snippet fallback()}8 <div>Loading chart...</div>9 {/snippet}1011 <Chart />12</WhenMounted>1<script>2 import { WhenMounted } from "@inertiajs/svelte";3 import Chart from "@/Components/Chart.svelte";4</script>56<WhenMounted>7 {#snippet fallback()}8 <div>Loading chart...</div>9 {/snippet}1011 <Chart />12</WhenMounted>
The fallback only appears on the initial server-rendered page load. Subsequent visits, as well as applications not using SSR, render the children immediately.
JSX children are evaluated before WhenMounted renders, so expressions that access window directly still run on the server. You may pass a function as the children to defer their evaluation until the component mounts.
1<WhenMounted fallback={<div>Loading chart...</div>}>2 {() => <Chart width={window.innerWidth} />}3</WhenMounted>1<WhenMounted fallback={<div>Loading chart...</div>}>2 {() => <Chart width={window.innerWidth} />}3</WhenMounted>
Note that WhenMounted only skips rendering on the server. The wrapped component is still part of your SSR bundle, so its module must be safe to import on the server.
Deployment
When deploying your SSR-enabled app to production, you'll need to build both the client-side and server-side bundles, and then run the SSR server as a background process, typically using a process monitoring tool such as Supervisor.
1php artisan inertia:start-ssr1php artisan inertia:start-ssr
1node bootstrap/ssr/app.js1node bootstrap/ssr/app.js
Ensure bootstrap/ssr/app.js is built before starting your Laravel binary, as outside debug mode Laravel checks for the bundle once on startup.
To stop the SSR server—for instance when you deploy a new version of your website—you may utilize the inertia:stop-ssr Artisan command. Your process monitor (such as Supervisor) should be responsible for automatically restarting the SSR server after it has stopped.
1php artisan inertia:stop-ssr1php artisan inertia:stop-ssr
Laravel PHP Adapter v3.4.0+
By default, the command fails when the SSR server is not running. You may pass the --graceful option to return a successful exit code instead, making it ideal for deployment scripts where the SSR server is not yet running.
1php artisan inertia:stop-ssr --graceful1php artisan inertia:stop-ssr --graceful
Laravel PHP Adapter v3.6.0+
Before starting, the inertia:start-ssr command sends a shutdown request to the configured SSR URL to stop any server that is still running. Behind a load balancer, where several SSR servers share the same URL, this request may stop a different server that is still serving requests. You may pass the --no-stop-before-start option to skip the shutdown request.
1php artisan inertia:start-ssr --no-stop-before-start1php artisan inertia:start-ssr --no-stop-before-start
You may use the inertia:check-ssr Artisan command to verify that the SSR server is running. This can be helpful after deployment and works well as a Docker health check to ensure the server is responding as expected.
1php artisan inertia:check-ssr1php artisan inertia:check-ssr
By default, a check is performed to ensure the server-side bundle exists before dispatching a request to the SSR server. In some cases, such as when your app runs on multiple servers or is containerized, the web server may not have access to the SSR bundle. To disable this check, you may set the inertia.ssr.ensure_bundle_exists configuration value to false.
Laravel Cloud
To run the SSR server on Laravel Cloud, you may use Cloud's native support for Inertia SSR.
Laravel Forge
To run the SSR server on Forge, you may enable it via the Inertia SSR toggle in your site's application panel. Forge will create the required daemon and, optionally, update your deploy script to restart the SSR server on each deployment.