How to configure PhpStorm Remote Xdebug path mapping

10,605

Solution 1

I could fix this problem, PhpStorm can not handle if serverName is not configured.

What to do:

1. Setup environment variables:

export XDEBUG_CONFIG="idekey=PHPSTORM"
export PHP_IDE_CONFIG="serverName=web_server_cli"

2. Setup path mapping for that servername:

Go to Settings > Languages & Frameworks > PHP and create a server with a hostname web_server_cli

Solution 2

settings > languages and frameworks > php > servers Add your server, and add your path mapping! An example would be C:\Sites\mysite mapped to remote /var/www/mysite or similar

Solution 3

You need to set up a "server" configuration in "Settings > Languages and Frameworks > PHP > Servers" which maps the paths as seen on the server to the paths in your project.

Normally, you would enter a URL into "Host" and set "Port" to the HTTP port, e.g. 80 or 443. For CLI scripts, the info to put in here will be based on your connection to the server where the CLI script runs. For instance, if you SSH to 192.168.42.42 on the standard SSH port (22), you would enter "Host: 192.168.42.42", and "Port: 22".

To find out what details you need to set up, go into "Settings > Languages and Frameworks > PHP > Debug", enable "Force break at the first line when no path mapping specified", and make sure "Ignore external connections through unregistered server configurations" is not ticked. Then click "Listen for debug connections" in the toolbar, and run your script; a dialog box should pop up showing the "Server name:" and "Server port:" it is trying to match, as well as confirming the remote file path. Click "Ignore" on that dialog, set up the server mapping, and try again, and you should get a proper debug session.

Solution 4

From your comment to @delboy1978uk's answer, it looks like you want to debug a PHP script you are running from the command line. To effectively debug this, then rather than debugging this via a 'PHP Remote Application' run configuration (which PHPStorm will assume you are running via a browser) you will need to:

  1. Create a 'PHP Script' run configuration with the required arguments to run your CLI application.
  2. Set up a Remote CLI PHP interpreter (I run via IDEA, so for me this is located in Settings > Languages & Frameworks > PHP > CLI Interpreter, YMMV) and supply it with the SSH credentials used to connect to your vagrant box
  3. Initiate your Script via the run configuration in Debug Mode.

If all is set up correctly, your CLI script will start and use the breakpoints correctly.

Share:
10,605
fobus
Author by

fobus

Updated on June 27, 2022

Comments

  • fobus
    fobus almost 2 years

    I have setup and docker machine that runs my application. In this docker machine xdebug is enabled with these xdebug.ini settings.

    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so
    xdebug.remote_enable=on
    xdebug.remote_enable=1
    xdebug.remote_port=9000
    xdebug.remote_host=10.5.0.1
    

    My local machines IP is 10.5.0.1

    When I try to run my application on command line, it connects back to PhpStorm debugger. But because of there is no path mapping it stops at the first line of the script, break points doesn't work. Break point cursor is not visible, I can't track the code by F8 key.

    Also, it must show some kind of path mapping error Debugger->Variables windows, but it doesn't show any error.

    How to fix this?