Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bilal_swl's avatar

How correctly Deploy Laravel on Heroku

I just create laravel app with staterkit (breeze) and i am using (react) inertiajs. I pushed the code to Heroku, it's showing error 419 while register and login. I haven't even started coding. I setup all environment variables on heroku. I try same thing with blade files, but it's working perfectly. How I can push and configure environment variable correctly. Error: 419

0 likes
7 replies
Bilal_swl's avatar

@jlrdw brother I follow all the documentation. But it's work when I use blade engine. While using Inertiajs (with reactjs), it's give error 419 even on login and register page (starter kit: breeze). I want best solution/way to prevent this error. Error not exist when I use on localhost.

martinbean's avatar

@bilal_swl What values have you defined for things like CACHE_STORE and SESSION_DRIVER?

Heroku has an ephemeral file system. This means nothing is persisted. So if you’re using say, file for SESSION_DRIVER then that’s not going to work, as you’ll get a different dyno serving each request. So if you load a page, and a CSRF token is generated and stored in a file, then that file is not going to be available when you submit the form and a completely different dyno is handling the POST request.

You’ll need to instead use something like database or redis drivers for things like the cache and sessions. You’ll also need to use something other than local for FILESYSTEM_DISK as again, you can’t store files locally in a Heroku app, as the files will disappear after the node has handled the request. Instead, you’ll need to use something like the s3 driver.

Bilal_swl's avatar

@martinbean I also try database as SESSION_DRIVER but still same. can you provide any video tutorial. I want push Laravel app (with inertiajs/reactjs). I will be very thankful.

martinbean's avatar

@Bilal_swl So re-deploy your application after changing the SESSION_DRIVER to database, and then tell us what the problem is.

You can also try connecting to the database (assuming you’ve actually added one to your app) to see if any rows are being inserted into your sessions table.

So, to avoid making assumptions, what database add-on are you using for your application in Heroku?

Bilal_swl's avatar

@martinbean In App\Providers\AppServiceProvider.php, i add

public function boot()
{
    \URL::forceScheme('https');
}

now its working perfectly

martinbean's avatar
Level 80

@Bilal_swl You should be configuring the trusted proxies to correctly detect HTTPS instead.

Laravel 10.x

Docs: https://laravel.com/docs/10.x/requests#configuring-trusted-proxies

class TrustProxies extends Middleware
{
    protected $proxies = '*';
    protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB;
}

Laravel 11.x

Docs: https://laravel.com/docs/11.x/requests#configuring-trusted-proxies

->withMiddleware(function (Middleware $middleware) {
    $middleware->trustProxies(
        at: '*',
        headers: Request::HEADER_X_FORWARDED_AWS_ELB,
    );
})

Please or to participate in this conversation.