简体   繁体   English

如何从其他计算机访问我的本地主机服务器?

[英]How can I access my localhost server from other computers?

I'm new to PHP, so I don't know how to explain it.我是PHP的新手,不知道怎么解释。 I'm running WAMP on my computer and I would like to be able to access my localhost from another computer .我在我的电脑上运行 WAMP,我希望能够从另一台电脑访问我的本地主机。

Is it possible?可能吗? How can I do this?我怎样才能做到这一点?

This is provided that all machines are on the same.network and that you have administrative privileges on the machines (you'll have to edit some system files).前提是所有机器都在同一个网络上,并且您对这些机器具有管理权限(您必须编辑一些系统文件)。

You can easily do this but it would have to be a manual process.您可以轻松地做到这一点,但它必须是一个手动过程。

You have to create an entry in the hosts file -您必须在主机文件中创建一个条目 -

  • On Windows machines is is located in %SystemRoot%\system32\drivers\etc\hosts在 Windows 机器上位于%SystemRoot%\system32\drivers\etc\hosts
  • On UNIX like systems it is located in /etc/hosts在类似 UNIX 的系统上,它位于/etc/hosts

http://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system . http://en.wikipedia.org/wiki/Hosts_(file)#Location_in_the_file_system
See the link for details on where your hosts file is located.有关主机文件所在位置详细信息,请参阅链接。 It depends on the operating system.这取决于操作系统。


The following will have to be done on every machine that you would like必须在您想要的每台机器上完成以下操作
to have access to your localhost machine.可以访问您的localhost

Add a line at the very end of your hosts file similar to this:在 hosts 文件的末尾添加一行,类似于:

10.0.0.42       prathyash-localhost.com

The IP address (in the example above it is 10.0.0.42 ) is the address of your localhost; IP 地址(在上面的示例中为10.0.0.42 )是本地主机的地址; Your computers IP address.你的电脑IP地址。 The domain name ( prathyash-localhost.com ) is what is mapped to the IP address.域名 ( prathyash-localhost.com )映射到 IP 地址。

After you save that file, whenever that computer points to prathyash-localhost.com , it will be directed to your IP address.保存该文件后,每当计算机指向prathyash-localhost.com时,它将被定向到您的 IP 地址。 Firewalls are still a barrier - however the other answers covered that so I will not repeat their contribution.防火墙仍然是一个障碍——但是其他答案涵盖了这一点,所以我不会重复他们的贡献。


Depending on your situation, manually editing tens maybe hundreds of files might not be feasible.根据您的情况,手动编辑数十个或数百个文件可能不可行。 In this case, you might want to consult the.networks administrator (he probably hangs around on Server Fault ), and he may have a better solution for you.在这种情况下,您可能需要咨询 .networks 管理员(他可能在Server Fault上闲逛),他可能会为您提供更好的解决方案。

This problem can be fixed as follows.This is for one using a wamp server or a similar local server.此问题可以按如下方式解决。这是针对使用 wamp 服务器或类似本地服务器的问题。 first ensure that you have modified the httpd.conf.scroll until you find this line:首先确保您已经修改了 httpd.conf.scroll 直到找到这一行:

#  onlineoffline tag - don't remove
Order Allow,Deny
Allow from all

If you have a smartphone turn on your wifi hotspot to connect with your pc and the one you want to connect with.如果您有智能手机,请打开您的 wifi 热点以连接您的电脑和您想要连接的电脑。 Open the command prompt in your pc and type ipconfig.在您的电脑中打开命令提示符并键入 ipconfig。 Note down the ip4 address of your pc (eg. 192.168.43.47) under wireless LAN adapter Wireless Network Connection.在无线局域网适配器无线网络连接下记下您电脑的 ip4 地址(例如 192.168.43.47)。

In the pc you want to connect to set "Obtain IP address automatically".在你要连接的电脑上设置“自动获取IP地址”。 Before you connect ensure your wamp server is online.在您连接之前确保您的 wamp 服务器在线。 Open the browser of the client pc and type the IP address noted down earlier.This should work just fine.打开客户端电脑的浏览器并输入之前记下的 IP 地址。这应该可以正常工作。 In some cases you may be required to switch off your antivirus.在某些情况下,您可能需要关闭防病毒软件。

Yes if they are on the same.network, simply target the computer's IP address and ensure anything on either computer that would block access to port 80 (firewalls) is off是的,如果它们在同一个网络上,只需将计算机的 IP 地址作为目标,并确保任何一台计算机上阻止访问端口 80(防火墙)的任何东西都已关闭

@Shaun Hare explained it pretty good, however, if those computers are not in the same.network (my case, when remote presentation is needed) you would also need to set port forwarding on your router and remote side would need router's public IP address. @Shaun Hare解释得很好,但是,如果这些计算机不在同一个网络中(我的情况,当需要远程演示时),您还需要在路由器上设置端口转发,远程端需要路由器的公共 IP 地址.

Basically, remote side would enter http://123.123.123.123/index.php in their browser and router would point that request (via port forwarding) to WAMP server installed at 192.168.10.10 (for instance).基本上,远程端会在他们的浏览器中输入http://123.123.123.123/index.php ,路由器会将该请求(通过端口转发)指向安装在192.168.10.10 (例如)的 WAMP 服务器。

You can't.你不能。 Bind the appropriate daemon to 0.0.0.0/:: or an external interface and use the machine's IP address.将适当的守护程序绑定到 0.0.0.0/:: 或外部接口,并使用机器的 IP 地址。

If it's for testing you could use a service like http://localhost.run/ or https://ngrok.com/ to temporarily put localhost on the inte.net.如果用于测试,您可以使用http://localhost.run/https://ngrok.com/ 之类的服务来临时将 localhost 放在 inte.net 上。

Post forward port 80 on your router configuration.在您的路由器配置上发布转发端口 80 Start wamp.开始沼泽。 Now when your IP address is accessed from any external machine it will jump to the "www" folder and show the index file.现在,当从任何外部计算机访问您的 IP 地址时,它将跳转到“www”文件夹并显示索引文件。 If you are not able to do so, it means your firewall is blocking the request: Disable it and try again.如果您无法这样做,则意味着您的防火墙正在阻止该请求:禁用它并重试。

You could just tinker around the firewall.您可以修补防火墙。 I found that the inbound and outbound rules were blocking all public.network traffic (that is, all traffic to my router which is seen as public, even though it has a password) and proceeded to check the box to allow traffic on a public.network (both inbound and outbound) for all the rules bearing the Apache name.我发现入站和出站规则阻止了所有 public.network 流量(即,我的路由器的所有流量被视为公共,即使它有密码)并继续选中该框以允许公共流量。 Apache 名称的所有规则的网络(入站和出站)。 Also, I did turn on the mySQL server, but that shouldn't do anything at all in this matter (though life has surprised me like this before where something insignificant turned out to be quite significant in the end, so I would do this as a last resort, but unlikely).另外,我确实打开了 mySQL 服务器,但在这件事上它根本不应该做任何事情(尽管以前的生活让我感到惊讶,一些微不足道的事情最终变得非常重要,所以我会这样做最后的手段,但不太可能)。 Also, I think this should work at least over the same WiFi.network (and I know that's a part of LAN, but just to clear up any ambiguity) since I only tested with my Android phone (oh how I wish I had a Windows Phone).另外,我认为这至少应该在同一个 WiFi.network 上工作(我知道这是 LAN 的一部分,但只是为了消除歧义)因为我只用我的 Android 手机进行了测试(哦,我多么希望我有一个 Windows电话)。 Hope this of any use to anyone!希望这对任何人都有用!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从localhost访问PHP文件和SQL DB到同一网络上的其他计算机? - How to access PHP files and SQL DB from localhost to other computers on the same network? 如何使用本地IP地址而不是localhost访问数据库mysql服务器 - How can I access my database mysql server using my local ip address instead of using localhost 无法从本地网络上的 web 服务器访问 localhost - Can't access localhost from a web server on my local network 我如何在我的PC中使用php从其他网站动态自动自动将许多csv文件下载到localhost - How can i download many csv file dynamically automatic from other website to localhost in my pc in php 如何通过同一网络上的iPhone访问Mac localhost PHP服务器上的网站? - How can I access website on Mac localhost PHP server from an iPhone on the same network? 在本地主机上使用数据库的亚马逊AWS服务器,我如何ssh以便我可以在localhost上运行我的php webservices? - Amazon AWS server with database on localhost, how do I ssh so that my php webservices on localhost can run on it? 我可以从 same.network 上的其他设备访问在 localhost 中运行的 laravel 项目吗? - Can I access laravel project running in localhost from other devices on same network? 如何从本地运行的AngularJS应用程序中使用apache2代理设置访问localhost upload.php - How can I access localhost upload.php using apache2 proxy setting from my locally running AngularJS application 为什么我不能在我的托管域中使用 swiftmailer 发送邮件,但是从我的本地主机服务器发送邮件时没有错误 - Why can I not send mail with swiftmailer in my hosted domain but there is no error when sending it from my localhost server 如何从另一台设备访问在我的服务器上运行的 php web 页面? - How can I access my php web pages running on my server from another device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM