Mapping for debugging doesn't work for me with xDebug
I have an issue with mappings: they don't work for me then I debug. I googled dozens of websites and didn't found the solution. I want to share my experience:
First of all, setup xDebug with next settings for php-cli:
zend_extension=xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_mode=req
xdebug.profiler_enable=1
xdebug.profiler_output_dir=/tmp
Now, do the following:
1) Create a empty PHP project in some directory (let's says /home/user/src ) and create inside the project a script.php file.
2) Put some code inside that script, no matter what it would be, just few working lines of code
3) Create a directory /home/user/deploy and manually copy script.php file to that directory
4) Setup a path mapping for this file in Languages & Frameworks | PHP | Servers: add a new server, enter "localhost" in the Host, select Xdebug, select checkbox "Use path mappings...", add a mapping for "script.php" pointing to "/home/user/deploy/script.php".
5) In Languages & Frameworks | PHP | Debug be sure to select both "Force break first line ..." checkboxes and the "Break first line in PHP scripts" as well
6) Edit Configurations and create a new "PHP Script" Configuration: give it some name, and select /home/user/deploy/script.php as a file to run.
7) Launch the created configuration
Actual: PhpStorm opens a second tab for file /home/user/deploy/script.php with debug session stopped on the first line
Expected: PhpStorm understands that because of created mappings files /home/user/src/script.php and /home/user/deploy/script.php are the same file and doesn't open the second tab and displays debug session on file "src/script.php"
If you need more information I would like to provide it.
Thanks,
Dima
请先登录再写评论。
Hi,
So both /home/user/src and /home/user/deploy are both on the same local machine where PhpStorm is working too?
Sure, the same local machine.
Unfortunately it does not work like that.
First, Languages & Frameworks | PHP | Servers suggests that there's a web server. Path mappings won't work with CLI. So this whole section doesn't make any sense nor effect.
Second, PHP Script run configuration suggests there's a direct access to the file. And from all points of view (OS, file system etc), there are two different files so if we explicitly set the path to /home/user/deploy/script.php, it will run this script and since we checked Break at first line and Force break at first line when a script is outside the project, it will run the mentioned script that is currently outside of project directory and break on it according to the settings.
Whole case seems to be very synthetic for me so if you could describe why do you need this, it would be great.