A
A
Alexander Pankov2021-12-26 19:52:58
PHP
Alexander Pankov, 2021-12-26 19:52:58

How to set up xdebug for docker on vps?

Hello, I have a project, its files are with me and also on VPS from ubuntu
these files are mounted in a docker container (generally a php application)
I work in phpstorm

I can’t figure out how to set up xdebug in my case I edit files on my
laptop, these the files are immediately copied to the vps to a folder that
is forwarded to the docker container

(a thin client laptop, all the work of php + mysql + node + ...) happens on the vps,

as I understand it, you need to correctly configure xdebug.client_host
but I can’t connect everything in my head in a logical chain

I have one ip address
for vps another
inside the docker third

how to connect everything correctly?

config in php.ini

xdebug.mode = debug
; это мой ip и idekey котоырй в настройках пхпшторма и расширения браузера
xdebug.client_host = 46.229.184.75
xdebug.idekey = PHPSTORM
xdebug.client_port = 9003
xdebug.remote_connect_back = true
xdebug.start_with_request = yes


phpinfo shows that xdebug is
present xdebug_info also prints information
there is an error

[Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 46.229.184.75:9003 (through xdebug.client_host/xdebug.client_port) :-(

I don't 100% understand the docker network device, what do I need to write in the config so that I reach xdebug, which is on vps inside docker?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vamp, 2021-12-26
@PankovAlxndr

You have difficulty with the fact that xdebug is the initiator of the connection to your home ip. And if the home provider gives you a non-white IP, then such a connection cannot be made directly.
The solution could be port forwarding via ssh.
ssh -R 9003:172.17.0.2:9003 [email protected]
This command will establish an ssh connection with the user login to your vps at vpsaddr and open port 9003 on this server, which will be transparently proxied through the ssh connection to port 9003 already on your local computer.
You will only need to find out what is the local IP address of your container and substitute it for 172.17.0.2, which I specified for the example.
You can find it out with the command
docker inspect ваш-контейнер | grep IPAddress
This ip address must be registered in xdebug.client_hostand to the -R option instead of 172.17.0.2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question