skip to Main Content

I am using ngrok to port-forward a website hosted locally on my machine. The website was built using Laravel, Vue and PHP. When I access it locally (http://127.0.0.1:8000/) everything works well.

When I run ngrok (ngrok.exe http 8000), I can access it from my local machine using the new link, but not from other machines. On the other devices, it seems that it loads the header of the website but nothing else.

This is the ngrok link: https://e342-2001-56a-fa70-ee00-cde7-f078-3936-5705.ngrok-free.app

2

Answers


  1. try to use this library instead laravel-ngrok

    Login or Signup to reply.
  2. To configure ngrok with your Laravel application for local development, follow these steps:

    • Open the AppServiceProvider.php file located in your Laravel project.

    • Add the following code inside the boot method of the AppServiceProvider class:

      public function boot(IlluminateHttpRequest $request)
      {
          if (!empty(env('NGROK_URL')) && $request->server->has('HTTP_X_ORIGINAL_HOST')) {
              $this->app['url']->forceRootUrl(env('NGROK_URL'));
          }
      
          // Other code
      }
      
    • Open your terminal and run the following command, replacing laravel-site.test with the local URL your Laravel app uses:

      ngrok http -host-header=rewrite laravel-site.test:80
      
    • ngrok will provide you with a forwarding URL, typically in the format abc123.ngrok.io. Add the following line and replace abc123.ngrok.io with the URL you received from ngrok in the .env file:

      NGROK_URL=https://abc123.ngrok.io
      
    • Clear your app’s cache using the following commands in the terminal:

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

    For more: https://vanrossum.dev/5-using-ngrok-with-laravel

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search