Skip to content

Share localhost / Laravel

Share a Laravel app at a public URL

php artisan serve listens on localhost:8000, and whk share 8000 gives it an HTTPS link. Laravel answers any host, so the page loads at once; what needs attention is where its links and assets point.

# terminal 1: the dev server
php artisan serve

# terminal 2: the link
whk share 8000

The link is https://<name>.sharehooks.cc and works until you press Ctrl-C. No whk yet? Install it and log in, which takes a minute.

Start free:
or sign up with email

Laravel at a glance

Dev server
php artisan serve, port 8000
Share it
whk share 8000
Setting to add
No host setting: Laravel answers every Host unless you turned on trustHosts. Add trustProxies so generated URLs use the public name.
Without it
No error page. Links and assets from url(), route() and asset() point at http://localhost:8000, which is the visitor's own machine, so styles and scripts are missing.
Hot reload
Not through the link: Vite's dev server is a second port. Run npm run build and reload by hand.
URLs and cookies
trustProxies makes URLs use X-Forwarded-Host and X-Forwarded-Proto. APP_URL is for URLs made outside a request (Artisan, queues). Session cookies need no change.

Your dev server gets each request with Host: localhost:8000; the public name travels in X-Forwarded-Host, with X-Forwarded-Proto: https. What your server sees has the rest.

Trust the proxy, or URLs point at localhost

During a request Laravel generates URLs from the request's own scheme and host. Through the link those are http and localhost:8000, so every route(), url() and asset() call writes http://localhost:8000/... into the page. Redirects to such an address come back to the link, but a stylesheet or script tag does not: the visitor's browser looks for it on their own machine.

Laravel's TrustProxies middleware reads X-Forwarded-Host and X-Forwarded-Proto from proxies you name. whk runs on your machine, so the proxy to trust is the loopback address:

bootstrap/app.php

->withMiddleware(function (Middleware $middleware): void {
    // whk share connects from this machine, and sets only these headers
    $middleware->trustProxies(
        at: ['127.0.0.1', '::1'],
        headers: Request::HEADER_X_FORWARDED_FOR
            | Request::HEADER_X_FORWARDED_HOST
            | Request::HEADER_X_FORWARDED_PROTO,
    );
})

With that, generated URLs read https://<name>.sharehooks.cc/.... Request is Illuminate\Http\Request. Listing the headers matters because Laravel otherwise also trusts X-Forwarded-Port and X-Forwarded-Prefix, which the link passes through from the visitor unchanged. The docs also allow trustProxies(at: '*'), which trusts whatever connects; naming loopback is enough here.

Stop the Vite dev server and build

npm run dev (and composer run dev, which starts it for you) runs Vite on its own port and writes its address into public/hot. While that file exists, the @vite directive points script and style tags at the Vite server, such as http://localhost:5173 or http://[::1]:5173. A share is one port, so visitors get your HTML without its CSS and JavaScript.

For sharing, stop the Vite dev server (it removes public/hot on exit) and build once. @vite then loads the compiled files from public/build, served by php artisan serve on the shared port:

npm run build
php artisan serve
whk share 8000

Run npm run build again after changing CSS or JavaScript. Blade and PHP changes show on the next page load without a rebuild.

APP_URL, forms and sessions

APP_URL is what the console uses to generate URLs when there is no request: Artisan commands, queued mail, scheduled jobs. Set it to the link if those need to produce working links, which is practical with a reserved name that stays the same.

Forms work as they are. Laravel 13's PreventRequestForgery middleware first looks at the browser's Sec-Fetch-Site header, which says same-origin for a form posted from the link to the link, and falls back to the CSRF token. Neither compares hosts. Session cookies are set without a domain by default, so the browser keeps them for the link; leave SESSION_DOMAIN unset, because a cookie set for another domain is dropped on the way out.

If the port is taken, php artisan serve moves to the next one (8001, and on up to ten tries), so share the port it prints.

Laravel questions

Sources

The Laravel settings and messages on this page are from the official documentation and source for Laravel 13, read on 12 November 2026. What the link does to a request is from the whk share docs.

Other frameworks

All 14 framework guides

Send someone your Laravel app

Sign up free, install the CLI and run whk share 8000.

or sign up with email

No credit card