我在
php.ini
中设置了Debug config
和phpstorm
。尝试在 phpstorm 事件日志中调试 php 脚本输出:
"Error running script.php: Port 9000 is busy"
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"
pStorm 中的调试端口也设置为 9000。
netstat -na
输出为:
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
如果我设置为其他端口怎么办?例如,将其设置为
10001
似乎可以完成这项工作。或者只是如何让它正常工作。我不确定我是否理解 xDebug
的工作原理。这就像在 phpstorm 中运行 Debug("script.php")(Shift+F9)
并在文件中设置断点?
有人有想法吗?
编辑:
来自: 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.
如果我将端口更改为 9000 以外的端口怎么办?也许超过 50k 的东西。
GNU/Linux 解决方案(因为 Windows 之外还有生命):
按照@aqm的解决方案
首先找到使用端口9000的进程。
netstat -tulpn | grep :9000
您将得到如下输出:
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
您需要 PID 才能使用此命令杀死进程:
kill -9 3993
注意:也许你的进程没有显示他的PID,可能你正在运行使用默认端口9000的PHP-FPM,在这种情况下你可以更改PHP-FPM端口或PHP Xdebug端口。
解决方案 1 - 更改 Xdebug 配置:
编辑
/etc/php/php.ini
搜索
xdebug.remote_port=9000
并替换为您的新端口
解决方案 2 - 更改 PHP-FPM 端口:
编辑
/etc/php/php-fpm.conf
使用
listen = 127.0.0.1:9000
搜索行并将 9000 替换为您的新端口
然后重新加载服务:
systemctl reload php-fpm
然后编辑你的 nginx 或 apache 配置来告诉这个新端口,在
127.0.0.1:9000
或 /etc/httpd/httpd.conf
中搜索 /etc/nginx/nginx.conf
并将其替换为你的新端口
重新加载您的服务器:
systemctl reload nginx
或
systemctl reload httpd
我希望它有帮助:),
合十礼。
无法使用 lsof 和 netstat 识别在 9000 端口上运行的进程的 pid。临时最简单的解决方案就是将
phpstorm
和 php.ini
中的端口更改为其他未实际使用的端口(例如 10k)。
基本上其他一些进程正在使用 9000 并且不使用让它走,通常对我来说另一个 IDE 同时运行
Windows 修复 ->
打开cmd.exe
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
taskkill /PID XXXX
写给未来的自己:
就我而言,这是由于使用虚拟机端口转发(Virtual Box 上的 vagrant)引起的。我认为转发
9000
是个好主意。
解决方案:连接到VM IP
10.166.53.1
,这是标准的Virtual Box
我的
/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
首先,即使有点偏离主题,我认为它还是有帮助的。我为每个 docker-composer 项目使用不同的网络接口。这样我就可以在 /etc/hosts 中映射一个持久域名而无需担心,在这个例子中是
192.168.33.102 project.domain.local
。
这是 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"
php 容器在 9001 上监听
php7.0-fpm
,在 9000 上监听 xdebug
,并且不公开任何端口。
PhpStorm 调试端口设置为默认 9000,服务器主机设置为
192.168.33.102
(或 /etc/hosts 中的值,即 project.domain.local
)。
在php容器的端口中可以看到,不同的映射端口设置为10000,它可以是除9000之外的任何其他值,以消除PhpStorm的繁忙错误。
此外,在 docker-compose 上绑定端口也很重要。如果没有映射端口,它就无法工作,并且无法与 9000:9000 一起工作。
希望对其他人有帮助!
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
对我来说有效:
在 Linux 上使用
查看已使用的端口sudo netstat -tulpn | grep :90
结果
tcp 0 0 0.0.0.0:9000 0.0.0.0:* OUÇA 22719/docker-proxy
tcp6 0 0 :::9000 :::* OUÇA 22726/docker-proxy
tcp6 0 0 :::9003 :::* OUÇA 5252/java
然后我就变了
在 dockerfile 上:
&& echo "xdebug.client_port=9001" >> /usr/local/etc/php/conf.d/xdebug.ini \
以及 phpstorm 设置
设置 > PHP > 调试:
Xdebug部分:调试端口9001