S
S
sv82019-03-03 14:27:04
PHP
sv8, 2019-03-03 14:27:04

How to make friends Windows 10 + Docker + PhpStorm + Xdebug?

Good afternoon!
The second day I suffer with Xdebug'a setup.
Windows 10 OS, I use Docker ("Docker for Windows") to run applications.
There was a need to debug PHP code in PhpStorm. And ran into setting up the whole thing.
My current setup.
In the docker-file for the "php-container" I install xdebug:

pecl install xdebug; \
docker-php-ext-enable xdebug; \
echo "error_reporting=E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "display_startup_errors=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "display_errors=On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_host=10.0.75.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \

^ as "remote_host" I take the IPv4 address for the "Ethernet adapter vEthernet (DockerNAT)" (it seems like you need to do this for Windows). I take 9001 as "remote_port", because fastcgi occupies port 9000.
In PhpStorm, everything seems to be logically configured too:
5c7bb7ad3f0b3563952812.png
-
5c7bb805daee9174167488.png
^ I don't use "DBGp Proxy", I specify "ide key" in the remote debugger's settings (= PHPSTORM).
As a result , I run xdebug, open the required URL ... and in the console I see only this:
"Waiting for incoming connection with ide key 'PHPSTORM".
PS:
Spec. a chrome extension for xdebug is also worth it, it doesn't help.
Kindly, tell me, maybe I don’t see some obvious cant / don’t take it into account?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Denis Bondar, 2019-03-07
@denisbondar

Good afternoon.
I recently described the whole process in detail on my blog. Works guaranteed.
Welcome!
https://blog.denisbondar.com/post/phpstorm_docker_...

M
MKMatriX, 2020-09-17
@MKMatriX

The thing is how the network for docker under Windows is arranged, alas, you need to specify the IP address of the docker virtual adapter, otherwise no debug.
https://devilbox.readthedocs.io/en/latest/intermed...
As an example

A
Arkady Abramov, 2019-03-03
@aceventura

tcp/ip level
1. Make sure that the storm listens for connections on the port (the listen debug connection icon is green)
2. Make sure that you can reach the "parent" host from the docker at the address you specified in the configuration. telnet ip port.
3. Enable xdebug logging and see what will be in the log
Remote_autostart is not needed, turn it off.

N
Nikita Krasnikov, 2019-03-04
@YekitKsv

Remove remote_host and set connect_back to 1.
Also check that not only port 9000, but also 9001 is forwarded to the host.
When it works, do not forget to uncheck "force break at first line ..." in phpstorm in xdebug settings
. , so as not to write a cookie in each request to start a debug session.

I
Ivan Koryukov, 2019-03-05
@MadridianFox

I have defined for myself a universal approach for debugging in any network environment.
In the simplest case, when there is only one developer, and the server is behind NAT, you need to forward the port to the server via ssh.
At the same time, xdebug must be configured in php.ini so that it connects to localhost:9000.
When there are many developers, I use a modified dbgp proxy.
https://github.com/MadridianFox/php-xdebug-proxy
If it is on the same server as php, the xdebug settings are the same. The proxy is listening on port 9000. Each developer chooses a unique port for himself and forwards it via ssh to the server. You also need to forward port 9001 back to register your idekey in the proxy.
And most importantly - when registering your idekey through a storm, in the idekey field you need to write myidekey:9002
In the same window, the proxy port is 9001, the proxy host is localhost.
In the storm settings, we indicate that for debugging it is necessary to listen to port 9002.
In the browser, it doesn't matter if you use an extension or write XDEBUG_SESSION_START, you must specify myidekey without a port!
In the case of docker, you can either add an ssh server to a container with php itself, or raise an additional ssh container. With a single development, this is enough. Simply, depending on the location of ssh, you prescribe different hosts in xdebug. Throws a port there.
If there is more than one developer, allocate a container with ssh + dbgp proxy and each developer forwards his own port there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question