Using ngrok with Laravel · vanrossum.dev    

       vanrossum.dev 

 Article

Using ngrok with Laravel
========================

 ![](https://vanrossum.dev/images/jeffrey-portrait.webp) By Jeffrey van Rossum

  vanrossum.dev  

  [      vanrossum.dev ](https://vanrossum.dev)                      

  [ ← Writing ](https://vanrossum.dev/posts) 

If you like to temporarily expose your local development environment, you can do this with ngrok.

If you use Laravel Valet for development, you already [have ngrok available](https://laravel.com/docs/7.x/valet#sharing-sites). From your application's folder run the following command in the terminal:

```bash
valet share

```

If you don't use Valet, you'll have to install ngrok. You can do so by following the instructions at [ngrok.com](https://ngrok.com/)

Once you have ngrok installed, we need to do the following to make it work with your local Laravel app.

Open the AppServiceProvider.php file and add the following to the boot method:

```php
public function boot(\Illuminate\Http\Request $request)
    {
        if (!empty( env('NGROK_URL') ) && $request->server->has('HTTP_X_ORIGINAL_HOST')) {
            $this->app['url']->forceRootUrl(env('NGROK_URL'));
        }

        // other code
}

```

After you’ve done that, run the following command in your terminal. Make sure the URL is replaced with the local URL your Laravel app uses.

`ngrok http -host-header=rewrite laravel-site.test:80`

You’ll get a forwarding URL back. This URL, typically looking something like abc123.ngrok.io.

In your .env file, specify the property NGROK\_URL with the URL you have received from ngrok.

You might need to empty your app’s cache (from the terminal):

```
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan route:clear

```

  ![](https://vanrossum.dev/images/jeffrey-portrait.webp) Jeffrey van Rossum [@jeffreyrossum](https://x.com/jeffreyrossum) 

 share [𝕏](https://twitter.com/intent/tweet?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fusing-ngrok-with-laravel&text=Using+ngrok+with+Laravel) [WhatsApp](https://wa.me/?text=Using+ngrok+with+Laravel+https%3A%2F%2Fvanrossum.dev%2Fposts%2Fusing-ngrok-with-laravel) [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fvanrossum.dev%2Fposts%2Fusing-ngrok-with-laravel) 

   © 2026 Jeffrey van Rossum 

  vanrossum.dev vanrossum.dev
