1

I've done these steps:

  1. Setup remote server for deployment in PhpStorm.
  2. Setup docker server by SSH.
  3. Setup file map.
  4. Setup CLI Interpreter with remote docker.
  5. Map port 9003 from container to remote host, and forward this port by SSH to localhost.

Issues:

  1. "Run" test script not work with server + docker PhpStorm shows Could not open input file:/my/t.php message. I've tried changing path mapping to path/to/local/script, path/to/remote/script, path/to/docker/script and this did not do anything...
  2. "Validate Xdebug" did not worked because this validator creates a test file, uploads it to the server and try run the script. But my server run scripts from directory /pub/ but if I set this directory for upload script, PhpStorm adding /pub/ to the URL http://test.remote/pub and get answer 404
  3. I've tried to enable Listen for debug connection, enableed Xdebug extension in Google Chrome and set breakpoint on the first line, but connection was not established. Not working, I've checked 9003 port and it is allowed...
  4. I've tried to create test.php to try debugging a CLI script, but this doesn't work too, see point 1 "run" not working.

Software versions:

  1. PhpStorm - 2021.3
  2. PHP - 7.4
  3. Xdebug - 2.9.8

P.S. Sorry for my English.
P.P.S. I can't find manual how to setup PhpStorm, Xdebug with remote server in docker ((

6
  • "But my server run scripts from directory /pub/ but if I set this directory for upload script, PhpStorm adding /pub/ to the URL" That can be set up. It's a common scenario (e.g. Laravel project is served from a public folder). Commented Jan 20, 2022 at 15:12
  • "Xdebug - 2.9.8" Xdebug v2 is an old/deprecated version and no longer supported. Consider upgrading to Xdebug v3. Plus, it will be a bit easier to troubleshoot. xdebug.org/docs/upgrade_guide Commented Jan 20, 2022 at 15:12
  • "Map port 9003 from container to remote host, and forward this port by SSH to localhost." Not sure what has been done here. But I assume you use SSH tunnel here? jetbrains.com/help/phpstorm/… If so -- are you able to connect back from inside the docker back to the IDE? The plain telnet (or alternative) can help here (it can simply tell if a connection was successful or not) Commented Jan 20, 2022 at 15:15
  • Sadly cannot help with anything on the actual "remote docker" part. My Docker experience is limited to a local Docker Desktop (running on Windows). Commented Jan 20, 2022 at 15:16
  • @LazyOne how to connect from server to idea with telnet? Commented Jan 21, 2022 at 9:37

1 Answer 1

0

In my case, being in a similar situation, a solution was found in this SO answer. Namely, that was to update the remote host's /etc/ssh/sshd_config with

GatewayPorts clientspecified

and restart the sshd service. You can test to make sure you didn't make any mistakes in your SSH config with sshd -t if the service is already running.

This permitted me to set up a remote port forwarding bound to all interfaces on the remote host, not just localhost (the sshd default, for security).

ssh -R *:9003:localhost:9003 remotehost

There are security ramifications to this, but for an internal host on a private network, the tradeoffs might be tolerable. You could also use the IP address which host.docker.internal resolves to inside the container, if you wanted to be a bit more explicit. This would typically be a private Class B like 172.17.0.1.

Without specifying the remote bind address as above, the container can't actually reach localhost:9003 on the host, where the port being forwarded by your running ssh -R is situated.

This all assumes you're not using use network_mode: host in a Docker Compose config file, or launching your container with --network=host. In that case, localhost inside the container is localhost for the host operating system. This is a completely different approach and beyond the scope of your question, but would simplify the process above quite a bit if that were your actual setup.

One last tip: PhpStorm seems to figure out path mappings between your local copy of the code and the copy in the container pretty well on its own. VS Code or Codium, not so much, so you'll need to specify a pathMappings in your launch.json that accurately maps the path inside the container to a path on your local filesystem—that is, if you're not using one of the many, many "remote" solutions for VS Code, which can sometimes be more trouble than they're worth.

Hope that helps (someone)!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.