Linux 运行 script.php 时出错:端口 9000 正忙

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19109240/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:58:15  来源:igfitidea点击:

Error running script.php: Port 9000 is busy

phplinuxportxdebugphpstorm

提问by Jacob

I set php.iniand Debug configin phpstorm. Trying to debug php script outputs in phpstorm Event log with:

我设置php.iniDebug configphpstorm. 尝试使用以下命令调试 phpstorm 事件日志中的 php 脚本输出:

"Error running script.php: Port 9000 is busy"

end of php.ini:

php.ini 结尾:

        [XDebug]
        zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
        xdebug.remote_enable=1
        xdebug.remote_port="9000" (the default port is 9000)
        xdebug.profiler_enable=1
        xdebug.profiler_enable_trigger = 1
        xdebug.profiler_output_dir="/etc/php5/xdebug/profiler_output_dir"

Debug port in pStorm is also set on 9000. netstat -naoutputs with:

pStorm 中的调试端口也设置在 9000. netstat -na输出上:

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN 

What if I set to other port. eg setting it to 10001seems to do the job. Or just how to make it work properly. I am not sure if I understand how the xDebugworks. Its like running Debug("script.php")(Shift+F9)in phpstorm with set breakpoint in file ?

如果我设置为其他端口怎么办。例如将其设置为10001似乎可以完成这项工作。或者只是如何使它正常工作。我不确定我是否理解它是如何xDebug工作的。就像Debug("script.php")(Shift+F9)在 phpstorm 中运行并在文件中设置断点一样?

Does somebody have an idea ?

有人有想法吗?

EDIT:

编辑:

From: http://xdebug.org/docs/remote

来自:http: //xdebug.org/docs/remote

xdebug.remote_port
Type: integer, Default value: 9000
The port to which Xdebug tries to connect on the remote host. Port 9000 is the default for both the client and the bundled debugclient. As many clients use this port number, it is best to leave this setting unchanged.

What if I change port for other than 9000 ? Maybe something over 50k .

如果我更改 9000 以外的端口怎么办?也许超过 50k 的东西。

采纳答案by Jacob

Could not identify with lsof and netstat the pid of process running on 9000port. Temporary simplest sollution is just to change the port in phpstormand php.inifor something else not actually used (like 10k).

无法使用 lsof 和 netstat 识别在9000端口上运行的进程的 pid 。临时最简单的解决方案只是更改端口phpstormphp.ini其他未实际使用的端口(例如10k)。

回答by aqm

Basically some other process is using 9000 and not using letting it go, normally for me another IDE running at the same time

基本上其他一些进程正在使用 9000 而不是使用放手,通常对我来说另一个同时运行的 IDE

Windows fix ->

Windows 修复 ->

  1. FIND PROCESS USING 9000
  1. 使用 9000 查找进程

open up cmd.exe

打开cmd.exe

netstat -o

netstat -o

C:\Users\AMC75>netstat -o

Active Connections

 Proto  Local Address          Foreign Address        State           PID
 TCP    10.6.176.132:27018     livlt0124661:55375     ESTABLISHED     11104
 TCP    10.6.176.132:49271     chilynfe01:5061        ESTABLISHED     10120
 TCP    10.6.176.132:49379     hhefs14:netbios-ssn    ESTABLISHED     4
 TCP    10.6.176.132:49383     chifs08:netbios-ssn    ESTABLISHED     4
 TCP    10.6.176.132:51034     157.55.56.143:40002    ESTABLISHED     11104
 TCP    10.6.176.132:51038     db3msgr6011007:https   ESTABLISHED     11104
 TCP    10.6.176.132:51049     wb-in-f125:5222        ESTABLISHED     10860
 TCP    10.6.176.132:51282     wpapp020:50124         ESTABLISHED     848
 TCP    10.6.176.132:53014     ec2-107-23-104-135:https  ESTABLISHED     10860
 TCP    10.6.176.132:53015     ec2-107-23-104-135:https  ESTABLISHED     10860
 TCP    10.6.176.132:54774     157.56.116.205:12350   ESTABLISHED     11104
 TCP    10.6.176.132:54822     a23-198-48-60:https    CLOSE_WAIT      7500
 TCP    10.6.176.132:55166     upmon070:3306          ESTABLISHED     2652
 TCP    10.6.176.132:55261     lhr08s03-in-f9:http    ESTABLISHED     10860
 TCP    10.6.176.132:55570     upmon070:3306          ESTABLISHED     10980
..... BLAH BLAH BLAH
  1. KILL PROCESS
  1. 杀死进程

taskkill /PID XXXX

taskkill /PID XXXX

  1. PROFIT ... ?, well you should now be able to run the debugger
  1. PROFIT ... ?,您现在应该可以运行调试器了

回答by Lyoneel

GNU/Linux Solution (because there is life beyond Windows) :

GNU/Linux 解决方案(因为 Windows 之外还有生命):

Following the solution of @aqm

遵循@aqm的解决方案

first find process using port 9000.

首先使用端口 9000 查找进程。

netstat -tulpn | grep :9000

You will get an output like this:

你会得到这样的输出:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      3993/programname

You need PID to kill process with this command:

您需要 PID 使用此命令终止进程:

kill -9 3993


NOTE: Maybe your process not show his PID, is possible that you are running PHP-FPM that uses as default port 9000, in this case you can change PHP-FPM port or PHP Xdebug port.

注意:也许您的进程没有显示他的 PID,可能您正在运行使用默认端口 9000 的 PHP-FPM,在这种情况下,您可以更改 PHP-FPM 端口或 PHP Xdebug 端口。



SOLUTION 1 - Changing your Xdebug configuration:

解决方案 1 - 更改您的 Xdebug 配置:

edit /etc/php/php.ini

编辑 /etc/php/php.ini

search for xdebug.remote_port=9000and replace with your new port

搜索xdebug.remote_port=9000并替换为您的新端口



SOLUTION 2 - Changing PHP-FPM Port:

解决方案 2 - 更改 PHP-FPM 端口:

Edit /etc/php/php-fpm.conf

编辑 /etc/php/php-fpm.conf

Search line with listen = 127.0.0.1:9000and replace 9000 with your new port

listen = 127.0.0.1:9000使用新端口搜索行并将 9000 替换为

then reload service:

然后重新加载服务:

systemctl reload php-fpm

Then edit your nginx or apache config to tell this new port, search for 127.0.0.1:9000in /etc/httpd/httpd.confor /etc/nginx/nginx.confand replace it with your new port

然后编辑您的 nginx 或 apache 配置以告诉这个新端口,搜索127.0.0.1:9000in/etc/httpd/httpd.conf/etc/nginx/nginx.conf并将其替换为您的新端口

reload your server:

重新加载您的服务器:

systemctl reload nginx

or

或者

systemctl reload httpd


I hope it helps :),

我希望它有帮助:),

namaste.

合十礼。

回答by Maciej Jankowski

note to future self:

给未来的自己注意:

In my case this was caused by using the virtual machine port forwarding (vagrant on Virtual Box). I thought forwarding 9000was a good idea.

就我而言,这是由于使用虚拟机端口转发(Virtual Box 上的 vagrant)造成的。我认为转发9000是个好主意。

SOLUTION: connect to VM IP 10.166.53.1which is the standard Virtual Box enter image description here

解决方案:连接到10.166.53.1标准 Virtual Box 的 VM IP在此处输入图片说明

contents of my /etc/php5/cgi/conf.d/xdebug.ini

我的内容 /etc/php5/cgi/conf.d/xdebug.ini

; xdebug configuration
; xdebug.remote_host = localhost
zend_extension =  /usr/lib/php5/20121212/xdebug.so
xdebug.remote_connect_back = 1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req
xdebug.idekey = "PHPSTORM"
xdebug.remote_log = /var/log/xdebug.log

回答by AVRAMESCU Razvan

First, even if is a little off topic, I think it helps. I am using a different network interface for each docker-composer project. This way I can map a persistent domain name in /etc/hosts without any worries, in this example is 192.168.33.102 project.domain.local.

首先,即使有点偏离主题,我认为它有帮助。我为每个 docker-composer 项目使用不同的网络接口。这样我就可以毫无顾虑地在 /etc/hosts 中映射一个持久域名,在这个例子中是192.168.33.102 project.domain.local.

Here is an example of yaml setup:

这是 yaml 设置的示例:

nginx:
  build: docker-images/nginx
  links:
    - "php"
  ports:
    - "192.168.33.102:80:80"
php:
  build: docker-images/php/7.0.1-fpm
  ports:
    - "192.168.33.102:10000:9000"

The php container listen on 9001for php7.0-fpmand on 9000for xdebugand does not expose any ports.

在PHP的容器监听9001php7.0-fpm9000xdebug和不公开任何端口。

PhpStorm Debug Port is set to default 9000 and the server host is set to 192.168.33.102(or the value from /etc/hosts, which is project.domain.local).

PhpStorm 调试端口设置为默认 9000,服务器主机设置为192.168.33.102(或 /etc/hosts 中的值,即project.domain.local)。

As can be seen in the ports of php container, a different mapping port is set to 10000, it can be any other different value than 9000, to remove the busy error from PhpStorm.

在php容器的ports中可以看到,不同的映射端口设置为10000,可以是9000以外的任何其他值,以消除PhpStorm中的busy错误。

Also, it is important to bind the port on docker-compose. It did not worked without mapping the port and it did not work with 9000:9000.

此外,在 docker-compose 上绑定端口也很重要。如果没有映射端口,它就无法工作,并且无法与9000:9000 一起使用

Hope it helps someone else!

希望它可以帮助别人!

PS: here is the xdebug.ini:

PS:这里是xdebug.ini:

zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

回答by Philipp Michael

The process, which is running on port 9000, could be PhpStorm itself.

在端口 9000 上运行的进程可能是 PhpStorm 本身。

Check the currently used ports like Jacob mentioned (on Windows cmd: netstat -a -b): enter image description here

检查当前使用的端口,如 Jacob 提到的(在 Windows cmd: 上netstat -a -b): 在此处输入图片说明

If PhpStorm.exeist listed under :9000you just have to change the port of built-in serverin settings > Build, Execution, Deployment > Debuggerto e.g. 63342(this was the default setting of my teammates PhpStorm installation).

如果PhpStorm.exe列在:9000 下,您只需在设置 > 构建、执行、部署 >调试器中将内置服务器的端口更改为例如63342(这是我的队友 PhpStorm 安装的默认设置)。