Xdebug randomly comes in as a server named underscore, times out

My configuration worked for half an hour, then just suddenly started showing this odd pop-up:

I was testing from Postman. Clicking Accept just saves it as a server named "_" with port 80 (even though our port is 8282 and that server is already saved), which was probably coming through WSL2 (from our Docker container, which is all configured in PHPStorm).

Like I said, everything was working fine for like 30 minutes, then this just randomly started showing up... I've reconfigured everything I could in PHPStorm, and double-check everything I could in WSL2 and Docker.

Does anyone know what to do here?! Or seen this? I don't know why it's coming through as a nameless server on the wrong port suddenly when it was working fine for a while. I'm completely flabberghasted.

0
11 comments

Do you have "Break at first line in PHP Scripts" checkbox set at File | Settings | Languages & Frameworks | PHP | Debug? Try removing it.

Some web server is running on port 80 in your environment and IDE is catching the request. 

The underscore name comes from a web server's $_SERVER['SERVER_NAME'].

1

No, that option was unchecked; I think it's unchecked by default. When I check it and try again, the box still comes up with server "_" port 80 (from WSL2 I'm guessing) even though my Postman is running localhost:8282 (on a Docker container inside the WSL2).

I've been trying to troubleshoot this over the weekend and nothing I'm trying to is fixing it, even though it was working and randomly stopped working even though I hadn't changed settings in-between.

Documentation and posts online report similar issues, but their configs are all different than our particular one, which seems to be fairly particular or uncommon, so I'm trying to trace where in logs or something to look to see why it's happening. I'm guessing I should start with Xdebug logs on the Docker container, then maybe server logs on WSL2, then somewhere PHP logs? I'm just unclear on what to do now to troubleshoot this.

 

0

1) Do you have /var/www/html/project/public/index.php in Docker only or in WSL as well?

2) Do you have anything running on a port 80 in WSL?

3) Try enabling "Ignore external connections through unregistered server configurations" checkbox at File | Settings | Languages & Frameworks | PHP | Debug

0

1) Do you have /var/www/html/project/public/index.php in Docker only or in WSL as well?

It's in Docker as /var/www/TheApp, and in WSL2 as ~/projects/TheApp. Making file changes in either place affects the other.

2) Do you have anything running on a port 80 in WSL?

I thought I did, but apparently not?

Me@WSL2:~$ sudo netstat -tulpn | grep LISTEN
tcp6 0 0 :::3000 :::* LISTEN -
tcp6 0 0 :::8282 :::* LISTEN -

3) Try enabling "Ignore external connections through unregistered server configurations" checkbox at File | Settings | Languages & Frameworks | PHP | Debug

I did that, and the Postman request runs just fine (gets data back) and PHPStorm does nothing; no pop-up, no notification, no event.

Here's what I gleaned from diving into our WSL2/Docker server config... $_SERVER SERVER_NAME has '_' (underscore):

[HTTP_HOST] => localhost:8282
[SCRIPT_FILENAME] => /var/www/TheApp/public/index.php
[SERVER_NAME] => _
[SERVER_PORT] => 80
[SERVER_ADDR] => 172.19.0.2
[REMOTE_PORT] => 44904
[REMOTE_ADDR] => 172.19.0.1
[SERVER_SOFTWARE] => nginx/1.14.2

The Docker container's config shows port 9000, my PHPStorm Xdebug setting page shows '9000,9003' (we never modified that page's defaults).

application@abc123:/etc/nginx/conf.d$ cat /opt/docker/etc/nginx/main.conf
include /opt/docker/etc/nginx/global.conf;
include /opt/docker/etc/nginx/php.conf;
include /opt/docker/etc/nginx/conf.d/*.conf;
include /opt/docker/etc/nginx/vhost.conf;
application@abc123:/etc/nginx/conf.d$ cat /opt/docker/etc/nginx/global.conf
# deprecated
application@abc123:/etc/nginx/conf.d$ cat /opt/docker/etc/nginx/php.conf
# deprecated
application@abc123:/etc/nginx/conf.d$ cat /opt/docker/etc/nginx/conf.d/*.conf
# placeholder
upstream php {
    server 127.0.0.1:9000;
}

The Docker container's vhost shows server_name '_' (underscore) and matches the root path:

application@abc123:/etc/nginx/conf.d$ cat /opt/docker/etc/nginx/vhost.conf
server {
    listen 80 default_server;

    server_name _ *.vm docker;

    root "/var/www/TheApp/public";
    index index.php;

    include /opt/docker/etc/nginx/vhost.common.d/*.conf;
}

Everything seems fine except for some reason PHPStorm is either being sent or catching incorrectly server '_' at port 80 instead of localhost:8282 as configured in my Servers page:

0

The port 9000,9003 in IDE settings is normal. It's set this way because XDebug 3 was released recently and its using port 9003 by default. 

Your $_SERVER has  [SERVER_PORT] => 80 - that's where the problem comes from. How did you setup the webserver to be running on 8282?

0

The server named '_' (underscore) is on the WSL2 install, and the 8282 server is on a Docker container running in the WSL2, where the docroot path of the website project is in the Docker container's /var/www/Project folder, which is just a reference to WSL2's ~/home/me/projects/Project folder, which I then make a Windows network mapped drive to which results in the path \\wsl$\Ubuntu-20.04\home\me\projects\Project.

I hope this makes sense.

The server and PHP text I pasted previously shows you the details. I honestly don't know why the WSL2 server name is set to underscore and 80, though it appears to be a default for WSL2 Ubuntu 20.04... not sure. Our developer who set up the project years ago isn't sure either, so he probably didn't manually do that. His Xdebug comes through properly as localhost:8282 (from the Docker container) yet we're not seeing why mine suddenly started coming through as the WSL server name and port.

It's very strange, and I'm hoping someone here has run into a similar issue using PHPStorm, WSL2, Docker, and Xdebug. I know it looks like a very particular or maybe even unusual setup, but those appear to be very modern and standard implementations for Laravel programming on Windows.

0

How is your port forwarding configured in docker-compose file? Could you please illustrate this?

0

It's really simple actually, everything is correct as before I got here:

version: "3.4"
services:
ourapp-app:
build:
context: ../../
dockerfile: "docker/dev/Dockerfile"
container_name: ourapp-dev
stdin_open: true
tty: true
ports:
- 8282:80
- 3000:3000
volumes:
- type: bind
source: ../../
target: /var/www/OurApp
0

Everything seems fine except for some reason PHPStorm is either being sent or catching incorrectly server '_' at port 80 instead of localhost:8282 as configured in my Servers page:

It's definitely a "being sent" here. When a debug session starts, PhpStorm performs some evals remotely to identify the server.

Here's what the typical session start looks like:

[21938] Log opened at 2021-01-28 14:16:13.903129
[21938] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[21938] [Step Debug] INFO: Connected to debugging client: localhost:9003 (through xdebug.client_host/xdebug.client_port). :-)
[21938] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/remote-webdebug1/index.php" language="PHP" xdebug:language_version="8.0.1" protocol_version="1.0" appid="21938" idekey="8123"><engine version="3.0.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2021 by Derick Rethans]]></copyright></init>

// Here, I omitted some irrelevant events, see the comments

[21938] [Step Debug] <- step_into -i 9
[21938] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="9" status="break" reason="ok"><xdebug:message filename="file:///var/www/remote-webdebug1/index.php" lineno="2"></xdebug:message></response>

[21938] [Step Debug] <- eval -i 10 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
[21938] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="10"><property type="bool"><![CDATA[0]]></property></response>

[21938] [Step Debug] <- eval -i 11 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[21938] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="11"><property type="bool"><![CDATA[1]]></property></response>

// Eval (string)($_SERVER['SERVER_NAME'])
[21938] [Step Debug] <- eval -i 12 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
// and the server returns localhost
[21938] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="12"><property type="string" size="9" encoding="base64"><![CDATA[bG9jYWxob3N0]]></property></response>

// Eval (string)($_SERVER['SERVER_PORT'])
[21938] [Step Debug] <- eval -i 13 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
// and the server returns 8080
[21938] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="13"><property type="string" size="4" encoding="base64"><![CDATA[ODA4MA==]]></property></response>

// More irrelevant events

The question is why your server returns wrong values sometimes, but I am afraid we will not be able to help you with that.

Also, why don't you just leave both of the records, the localhost one and the underscore one? I don't see how it can do any harm.

0

I'm not sure I understand that output. Is that Xdebug log, or PHPStorm log, or what? How did you generated it?

0

It's the Xdebug log. The <- events are PhpStorm commands, the -> events are Xdebug responses.

0

Please sign in to leave a comment.