Connect mobile device to vite using php development server: exposing host
P粉555682718
P粉555682718 2023-11-02 12:04:14
0
2
596

solution:

Thanks@parastoo, it works now. I have to start the development server like this (2 different terminal tabs):

vite --host=HOST_IP php artisan serve --host=HOST_IP

Then connect your mobile device (connected to your WiFi) to:

http://HOST_IP:PORT

HOST_IPcan be seen in the terminal when runningvite --host

PORTcan be configured by adding--port=8000to the artisan command.

No need to add any entries invite.config.js.

Original question

I'm using inertia, a holistic approach to developing applications with frontend frameworks likevueandlaravelas backend. I'm trying to connect a mobile device from my network to my development server usingviteandphp server:

  1. Run vite:
vite
  1. run php server:
php artisan serve

This site is served byhttp://localhost:8000. From How to expose "host" for display by external devices? #3396 I read that you can do something like this:

vite --host

This should expose your network:

vite v2.9.13 dev server running at: > Local: http://localhost:3000/ > Network: http://192.xxxxxxxxx:3000/ ready in 419ms.

But when I try to connect to the network url on my phone,this pagecannot be found. I also tried connecting to port8000, which saysThis site is unreachable.

Is there any way to make it work?

P粉555682718
P粉555682718

reply all (2)
P粉285587590

Your php terminal is running onlocalhost:8000

So you can run php artisanserve on the host.

php artisan serve --host=192.XXXXXXXX
    P粉235202573

    You should connect to the same network and then check your local IP and serve your Laravel project via:

    PHP artisan serve --host=xx.xx.xx.xx --port=xxxx

    **You should disable the firewall**

    updated

    Add this configuration to yourvite.config.jsfile

    server: { host: true }

    For example, this is my configuration file:

    import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; import vue from '@vitejs/plugin-vue'; export default defineConfig({ plugins: [ vue(), laravel({ input: ['resources/js/app.js'], refresh: true, }), ], server: { host: true } });

    Then run this command and add the hosts you are serving with Laravel:

    npm run dev -- --host=xx.xx.xx.xx

    These commands should be run with the same host:

    PHP artisan serve --host=xx.xx.xx.xx --port=xxxx npm run dev -- --host=xx.xx.xx.xx
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!