If you're not bound to using Apache or nginx for some special reason and this is for development purposes only, you could serve the application using the PHP built-in server and artisan
. It's by far the easiest thing to setup, and will only require you to run one command in the Laravel application directory:
php artisan serve --host 0.0.0.0
The default port it will be listening to will be 8000
to avoid any conflicts, so you can now access the application from your phone via the IP address of your computer:
http://192.168.1.101:8000
如果您想侦听另一个端口(例如,默认的HTTP端口80
),您可以将其作为参数传递,只需确保该端口上没有其他服务器在运行即可.因此,如果您运行此命令,请执行以下操作:
php artisan serve --host 0.0.0.0 --port 80
现在,您只需使用IP地址即可访问应用程序:
http://192.168.1.101