How to use ngrok with Laravel Breeze (Inertia + Vue.js) when using two different ports?
To use ngrok with Laravel Breeze (Inertia + Vue.js) when using two different ports, follow these steps:
-
Install ngrok:
- Download ngrok from https://ngrok.io/ and extract the zip file.
- Add the
ngrok
executable to your system's PATH.
-
Start ngrok for your Laravel application:
- Open a terminal or command prompt and navigate to your Laravel project directory.
- Start the Laravel development server:
php artisan serve --port=6000
(or any other port number you prefer). - Start ngrok with the following command:
ngrok http 6000
(replace 6000 with the port number you used for Laravel). - Wait for ngrok to create a secure tunnel. Once it's done, you'll see two URLs: one for HTTP and another for HTTPS. Copy the HTTPS URL.
-
Start ngrok for your Vue.js application:
- If you have your Vue.js application in a separate project, navigate to its directory and start the development server:
npm run serve --port=3000
(or any other port number you prefer). - Start ngrok with the following command:
ngrok http 3000
(replace 3000 with the port number you used for Vue.js). - Wait for ngrok to create a secure tunnel. Once it's done, you'll see two URLs: one for HTTP and another for HTTPS. Copy the HTTPS URL for the Vue.js application.
- If you have your Vue.js application in a separate project, navigate to its directory and start the development server:
-
Configure Laravel Breeze:
- Open your
.env
file in your Laravel project and set the following variables:
ReplaceVITE_BASE_URL=http://localhost:4141/api VITE_APP_API_URL=http://localhost:4141/api
4141
with the number that appears at the end of the ngrok HTTPS URL for your Laravel application.
- Open your
-
Configure Vue.js:
- Open your
vue.config.js
file in your Vue.js project and set the following variables:
ReplacedevServer: { proxy: { '*': { target: 'http://localhost:4141', ws: true, changeOrigin: true, }, }, },
4141
with the number that appears at the end of the ngrok HTTPS URL for your Laravel application.
- Open your
-
Test the setup:
- Start both servers:
php artisan serve --port=6000
andnpm run serve --port=3000
. - Open your Laravel application in a web browser using the HTTPS URL generated by ngrok for your Laravel application.
- Open your Vue.js application in a separate web browser tab using the HTTPS URL generated by ngrok for your Vue.js application.
- Make sure both applications can communicate with each other through the Laravel API.
- Start both servers:
That's it! You have successfully set up ngrok with Laravel Breeze (Inertia + Vue.js) when using two different ports.