简体   繁体   English

使用服务器内置的PHP构建的Google Cloud Shell问题-无法在端口8080上连接到Cloud Shell

[英]Google cloud shell problem with PHP built in server - could not connect to Cloud Shell on port 8080

I can't get to work my simple index.php file on Google cloud shell. 我无法在Google云外壳上使用简单的index.php文件。 I start my server with command php -S localhost:8080 -t test/ . 我使用命令php -S localhost:8080 -t test/启动服务器。 Before that I navigate just before test folder. 在此之前,我导航到测试文件夹之前。 I click Web preview in upper right corner and get error: Could not connect to Cloud Shell on port 8080 What could be the problem? 我单击右上角的Web预览并得到错误: 无法在端口8080上连接到Cloud Shell。可能是什么问题?

经过数小时的工作和重置...我只是从php -S localhost:8080 -t test/更改为php -S 127.0.0.1:8080 -t test

In Cloud Shell localhost resolves to both IPv4 and IPv6 addresses: 在Cloud Shell中,localhost解析为IPv4和IPv6地址:

$ head -3 /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback

It appears that when this is the case, PHP's builtin web server only binds to the IPv6 address ; 在这种情况下, PHP的内置Web服务器似乎仅绑定到IPv6地址 however, Cloud Shell web preview connects to the IPv4 addresses. 但是,Cloud Shell Web预览连接到IPv4地址。 Your solution to bind directly to the IPv4 loopback interface (127.0.0.1) is probably the best, for now. 目前,直接绑定到IPv4回送接口(127.0.0.1)的解决方案可能是最好的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM