Troubleshooting the problem that the breakpoint cannot be entered when PHPStorm+Xdebug performs emote Debug

Time:2022-9-20
Table of contents
  • Operating environment
  • Confirm that the PHP running the web program has the Xdebug extension installed
  • Confirm that the version of the Xdebug extension matches the PHP version
  • Confirm that Xdebug is configured with valid parameters
  • Confirm that the port that PHPStorm is listening on is the port configured in Xdebug
  • Confirm that the debugclient in PHPStorm starts successfully
  • Confirm that the IDEKey in PHPStorm is consistent with the configuration in Xdebug
  • The code is deployed remotely, and directory mapping needs to be enabled
  • Make sure the versions of PHPStorm and Xdebug+PHP match
  • Summarize

Recently, I have been studying the usage of Xdebug, mainly because Xdebug has greatly improved the development efficiency of PHP, but it can help us solve many problems. So here is a summary of the pits I encountered in configuring the PHPStorm+Xdebug environment, and some troubleshooting suggestions for friends who can't get into the breakpoint.

Operating environment

  • PHP Version 7.1.22
  • Xdebug v2.6.0
  • PHP2016.2;
  • Operating System: MacOS 10.12.3

If you encounter the problem of not being able to enter the breakpoint, you can follow the steps below to troubleshoot

Confirm that the PHP running the web program has the Xdebug extension installed

PHP is permanent, and it is inevitable that several more versions will be installed on the computer. At this time, you must pay attention to whether you have installed Xdebug into the PHP version you need to debug, and pay attention to the fact that the PHP running on the command line is not necessarily the PHP running by the Web program. For example, if you have installed PHP versions 5.6 and 7.1, the command line runs 5.6, but fpm runs 7.1. At this time, if you install Xdebug for 5.6, you can indeed see the Xdebug extension by running php -m | grep xdebug, but if you want to debug the web program running on 7.1, of course it is impossible. So the most important point here is:

Output phpinfo();exit; in the web program to confirm whether the Xdubug extension is installed in the php running fpm.

Confirm that the version of the Xdebug extension matches the PHP version

If you have Xdebug installed, but the version doesn't match PHP, it won't work. How to correctly choose the Xdebug version corresponding to PHP.

Confirm that Xdebug is configured with valid parameters

To debug different PHP programs in PHPStorm, you need to configure different Xdebug parameters. In Remote Debug mode:

The parameters that must be set are:

  • remote_enable=1 enables remote debugging. If this parameter is not enabled, Remote Debug cannot be enabled;
  • remote_host=127.0.0.1 (local condition) or remote_connect_back=1, since these two configuration items are closely related, they are put together. First of all, if you are targeting a single debugging user, such as debugging yourself, you can set remote_host to the ip where your web program runs (for example, this machine, set it to 127.0.0.1), and the value of remote_connect_back is not set or set to 0 (the default is also 0 if you don't set it). In this way, Xdebug will fixedly connect to the ip specified by remote_host every time it debugs; but if you support multi-person debugging, it is obviously impossible to set a remote_host. At this time, you can use remote_connect_back=1 to set. When remote_connect_back is set to 1, xdebug will automatically connect back according to the requested ip for debugging, thereby supporting multi-person debugging. At the same time, if this value is set to 1, the setting of remote_host will be invalid; in general, it is recommended to use the configuration of remote_connect_back=1
  • remote_port=9001 The port number used by the PHP process to communicate with DebugClient must be the same as that in PHPStorm, otherwise normal communication cannot be performed;
  • idekey=PHPSTORM can be understood as the password used for communication, which must be set consistent with that in PHPStorm;

Recommended parameters to set:

remote_autostart=1
By default, to trigger debugging, you need to add the get parameter to the url: XDEBUG_SESSION_START= {xdebug.idekey}. If you want to start debugging automatically, even without this parameter, you can automatically trigger debugging, you can set this value to 1, so it is recommended to set This value is set to 1;

Confirm that the port that PHPStorm is listening on is the port configured in Xdebug

Be sure to confirm here that the remote_port configured in Xdebug (preferably by printing out phpinfo) is the same as the one configured in PHPStorm, otherwise you cannot enter debugging.

Confirm that the debugclient in PHPStorm starts successfully

After starting Remote Debug in the PHPStorm toolbar, you need to check whether the DebugClient process is successfully started. This process is started by PHPStorm for debugging, so just check whether PHPStorm is listening on the port (remote_port) we set. For example, the port I specified is 9001, then on the Mac, I can passlsof -i tcp:9001Command to view:

Confirm that the IDEKey in PHPStorm is consistent with the configuration in Xdebug

Be sure to confirm that the IDEKey configured in PHPStorm is the same as the IDEKey configured in Xdebug, otherwise you cannot enter debugging.

The code is deployed remotely, and directory mapping needs to be enabled

If you are debugging a remote web program (that is, the code is not deployed on the local machine), you must set the directory mapping, otherwise the code cannot be found and cannot be debugged. The setting method is as follows:

Make sure the versions of PHPStorm and Xdebug+PHP match

Debugging with Xdebug is a process in which the PHP process communicates with the debugclient of PHPStorm through the Xdebug extension, so the three parties must be compatible in version. Sometimes I encounter some strange problems. For example, I have encountered a situation where I can enter the breakpoint, but cannot single-step debugging (click the next step to debug the process and it will be stuck). This situation is very likely that the version of PHPStorm is incompatible with the version of Xdebug+PHP. For example, the problem I encountered was because I used the latest version of Xdebug2.7, but the PHPStorm I used was the 2017.2 version, and I could debug normally after I lowered xdebug to 2.6. Therefore, it is best to ensure that the versions of PHPStorm, Xdebug and PHP are consistent.

Summarize

If it doesn't work according to the above, then you need to check the remote_log to see where the problem is.
At this time, you need to add to the configuration of xdebug:xdebug.remote_log=/tmp/xdebug.logto open remote_log.
After the configuration is complete, restart fpm, check phpinfo, and confirm that remote_log takes effect (by default, remote_log is not activated), and then you can debug.tail -f /tmp/xdebug.logto check the log. As an example, I deliberately set remote_port to a non-existent9999port, and then check the remote_log error message:

From the log, Xdebug tried to connect to port 9999 of 127.0.0.1, but failed. In this way, we can see where the problem lies. When we cannot find the configuration problem, we can use the log, combined with google and Baidu, to see if we can find the problem.

The above is the detailed content of the troubleshooting of the inability to enter breakpoints when PHPStorm+Xdebug performs emote Debug. For more information on PHP breakpoint troubleshooting, please pay attention to other related articles on developpaer!

Recommended Today

[Record] Using scaffolding to create plugin pits encountered by Vue3

Project ArchitectureVue3 + element-plus + echarts + axios + Gaode map + sass plugin packageamfe-flexible + postcss-pxtorem、vuex-persistedstate、sass-loader Create premise1. Upgrade the scaffolding to the latest2. Upgrade npm to the latestNote: Operate with administrator privileges error/warning error: ‘XXX’ is defined but never used (no-unused-vars) //Solution: add in package.json “rules”: { “generator-star-spacing”: “off”, “no-tabs”:”off”, “no-unused-vars”:”off”, “no-console”:”off”, “no-irregular-whitespace”:”off”, […]