NGrok and Laravel

Kaherdin picture Kaherdin · Apr 19, 2017 · Viewed 10k times · Source

I want to deploy my local larvel website online with NGROK. I'm using Laragon with Apache server, I use this command :

ngrok http -host-header=rewrite site.dev:80

It almost work, but the asset file (like CSS/Image) are still link to my local server (site.dev). And it's the same for my link, the laravel routing command : {{ route('ngo') }} return site.dev/ngo instead of my online tunnel (http://number.ngrok.io/ngo)

I've try to :

Edit the http.conf (https://forum.laragon.org/topic/88/allow-outside-other-devices-phones-tablets-to-access-your-local-server-using-ngrok)

Change my Laravel App url in config/app.php

Change my url in .env file

Nothings work

Answer

greew picture greew · Sep 1, 2017

I ran into this problem myself just now, but also found a way to fix it:

Run the ngrok command without the -host-header=rewrite part, resulting in

ngrok http site.dev:80

After this, edit your http.conf file and add the ngrok domain as a server alias. For example:

ServerAlias nd3428do.ngrok.io

The problem is that Laravel's route helper uses the HOST header, which is rewritten to site.dev. Without the -host-header part, the header isn't rewritten and now it works.