php 从外部设备本地访问 Laravel 5 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30675025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access to Laravel 5 app locally from an external device
提问by Bellots
I've looked for a solution in the web, but I've not found a solution yet. I need to access to my Laravel 5 app from my iPhone, but I'm in develop, so I don't want to publish my app on a web server.
我已经在网上寻找解决方案,但我还没有找到解决方案。我需要从我的 iPhone 访问我的 Laravel 5 应用程序,但我正在开发中,所以我不想在网络服务器上发布我的应用程序。
If you have a link to follow, that you assure it works, It's perfect for me.
如果你有一个链接,你可以确保它有效,这对我来说是完美的。
Thank you!
谢谢!
回答by Bogdan
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:
如果出于某些特殊原因,您不必使用 Apache 或 nginx 并且这仅用于开发目的,则可以使用 PHP 内置服务器和artisan
. 这是迄今为止最容易设置的事情,并且只需要您在 Laravel 应用程序目录中运行一个命令:
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:
它将侦听的默认端口是8000
为了避免任何冲突,因此您现在可以通过计算机的 IP 地址从手机访问应用程序:
http://192.168.1.101:8000
If you want to listen to another port (for example the default HTTP port of 80
) you can pass that as a parameter, just make sure no other server is running on that port. So if you run this instead:
如果您想侦听另一个端口(例如 的默认 HTTP 端口80
),您可以将其作为参数传递,只需确保该端口上没有其他服务器正在运行。所以如果你运行这个:
php artisan serve --host 0.0.0.0 --port 80
You can now access your application with just the IP address:
您现在可以仅使用 IP 地址访问您的应用程序:
http://192.168.1.101
回答by Elf Sundae
There are so many ways to do this.
有很多方法可以做到这一点。
- Access your web via IP address from your iPhone, e.g. http://192.168.1.100/laravel
- If your iPhone is jailbroken, you can edit iPhone's
/etc/hosts
file, the access your website via domain, e.g.laravel.com 192.168.1.100
- Upload laravel app to web server and config it a test domain, e.g.
dev.domain.com
, ordev.domain.com:8080
- If you can config your WiFi router, you can give your computer a "port forwarding" or set "DMZ"
Upload your website, and config "IP forbidden" roles, e.g. for Apache, edit your laravel's
.htaccess
file:Deny from all Allow from 180.159.251.175
- 通过 iPhone 的 IP 地址访问您的网页,例如http://192.168.1.100/laravel
- 如果你的 iPhone 越狱了,你可以编辑 iPhone 的
/etc/hosts
文件,通过域访问你的网站,例如laravel.com 192.168.1.100
- 将 Laravel 应用程序上传到 Web 服务器并将其配置为测试域,例如
dev.domain.com
,或dev.domain.com:8080
- 如果你可以配置你的WiFi路由器,你可以给你的电脑一个“端口转发”或设置“ DMZ”
上传您的网站,并配置“IP 禁止”角色,例如对于 Apache,编辑您的 Laravel
.htaccess
文件:Deny from all Allow from 180.159.251.175
回答by Ragabazh
Its simple, first you have to run the server
很简单,首先你要运行服务器
php artisan serve --host 0.0.0.0
Then you need to know what`s your IP address, run this command to get IP:
然后你需要知道你的IP地址是什么,运行这个命令来获取IP:
In windows:
在窗口中:
ipconfig
In Linux:
在 Linux 中:
hostname -I
For example, my IP is: 192.168.1.68
比如我的IP是:192.168.1.68
Once you get your IP, then you have to go to this address on your mobile. Like:
获得 IP 后,您必须在手机上访问此地址。喜欢:
192.168.1.68:8000
And that's it.
就是这样。
回答by Alex Kyriakidis
You can use Laravel Homestead, an official pre-packaged Vagrant "box" to develop your project and access your local website from multiple machines within the same private network.
您可以使用 Laravel Homestead,一个官方预打包的 Vagrant “盒子”来开发您的项目并从同一私有网络中的多台机器访问您的本地网站。
Here you can find more information about homestead and how to use it: http://laravel.com/docs/5.0/homestead
在这里你可以找到更多关于宅基地的信息以及如何使用它:http: //laravel.com/docs/5.0/homestead
And here a sample Vagrant private network setup: http://docs.vagrantup.com/v2/networking/private_network.html
这里有一个示例 Vagrant 专用网络设置:http: //docs.vagrantup.com/v2/networking/private_network.html
回答by Vladimir verleg
If you are having trouble using the accepted answers method, and you get page not found or similar errors, this is likely due to your firewall settings.
如果您在使用接受的答案方法时遇到问题,并且出现找不到页面或类似错误,这可能是由于您的防火墙设置所致。
回答by Roshan Chapagain
If
如果
php artisan serve --host 0.0.0.0
doesn't seem to work.
Try php artisan serve --host 0.0.0.0 --port 80
.
And access just using your IP address. For instance:
似乎不起作用。试试php artisan serve --host 0.0.0.0 --port 80
。只需使用您的 IP 地址即可访问。例如:
http://192.168.1.101