php -S localhost:port:表示永远等待localhost

时间:2016-01-25 15:41:04

标签: php

我安装了LAMP

我的phptest.php包含<?php phpinfo(); ?>

我试过了:

[.public_html]$ php -S localhost:54545 phptest.php 
[Mon Jan 25 21:06:52 2016] PHP Warning:  Module 'xdebug' already loaded in Unknown on line 0
PHP 5.6.14 Development Server started at Mon Jan 25 21:06:52 2016
Listening on http://localhost:54545
Document root is /home/simha/.public_html
Press Ctrl-C to quit.

然后我在Chrome中打开http://localhost:54545,然后显示waiting for localhost

我尝试http://localhost:81(为什么81见下文)和http://localhost:81/~simha所有这些都有效。它显示了各自的根目录。我的Apache看起来没问题。

还有一些关于hostcontainer的背景信息:

我安装了LAMP的Linux操作系统。使用systemd-nspawn我在容器中运行与LAMP相同的Linux操作系统。

我为主机LAMP设置了80端口,为容器LAMP设置了81端口

在主机系统中没有这样的问题。在php -S localhost:xxxxx phptest.php

之后,相同的文件将以铬的形式打开

但是在容器中,它只是说waiting for localhost

2 个答案:

答案 0 :(得分:0)

编辑: 我应该更清楚地知道,两个Web服务器(Apache和PHP -S)都在阻止连接的同一端口上运行,而不是正在访问的脚本。

如果您已经安装了LAMP,则无需运行public class AccountsManagementDetailsModel : UserInfo { public bool New { get; set; } } public class UserInfo { [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [Display(Name = "Username")] public string UserName { get; set; } [Required] [Display(Name = "First Name")] public string FirstName { get; set; } [Required] [Display(Name = "Last Name")] public string LastName { get; set; } public bool Customer { get; set; } public string CustomerID { get; set; } public bool MustChangePassword { get; set; } [DataType(DataType.Date)] [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd hh:mm}", ApplyFormatInEditMode = true)] public DateTime? LastLogin { get; set; } } 。您可能有两个Web服务器都试图访问相同的脚本,但只有其中一个可以执行,另一个被阻止:

Built-in web server

答案 1 :(得分:0)

默认情况下,容器的虚拟端口无论如何都不会连接到主机的物理端口。这就是为什么您无法访问容器内运行的PHP Web服务器的原因。您需要先将主机上的物理端口绑定到容器的虚拟端口

检查man page for systemd-nspawn并查找--port选项。

它采用以下格式:

--port=<protocol>:<host_port>:<container_port>

所以看起来像这样:

systemd-nspawn -bD /home/Mycontainer --port=tcp:80:54545

它将主机上端口80上的TCP重定向到容器上的端口54545。如果主机上的端口80已绑定(最可能是Apache),请使用另一个端口。

相关问题