(A) mounting xdebug PHP extensions, PHPStorm + XDebug Stepping
(B) Configuration PhpStorm XDebug
(C) PHPStorm debugging using XDebug
(D) PhpStorm + Xdebug configuration of a single-step debugging PHP
First, the principle:
Xdebug is a debugging php plugin, support for remote debugging on Windows or Linux. In the php file is run, sent through the TCP protocol debugging information to a remote port, IDE when you receive debugging information, it can run Xdebug to send a single step, halted, and run commands. This plug-in can also be code coverage statistics are interested in small partners can communicate together.
Second, the needs of the environment:
1. good web server has been built, according to the present embodiment using the Apache + PHP;
2. Xdebug a support remote debugging IDE, in this case using PhpStorm7, IDE Download: http: //www.jetbrains.com/phpstorm/;
3. a php corresponds with your version of Xdebug.
Third, server configuration
1. Download the corresponding version of PHP with Xdebug:
method one:
If you know php version used, directly to the official website to download the corresponding version of Xdebug, the official website address: http: //Xdebug.org/download.php.
Method Two:
. A If you do not know your PHP version, echo phpinfo ();
. B Press Ctrl + A copy the entire page;
C. Access http://Xdebug.org/wizard.php, copy and paste into a text box, as shown below.
. D Click on the page below "Analyse my phpinfo () output" button, the page will automatically analyze your php version, as shown below:
e. Click on the link back Download, download php version Xdebug your machine configuration matches.
f. 将下载的dll文件保存到PHP文件路径中的ext文件夹中。
2. 配置php.ini文件,连接Xdebug。
a. 打开PHP文件目录下的配置文件php.ini
b. 在文件的末尾添加如下设置:
[Xdebug] zend_extension = "E:\php\ext\php_Xdebug.dll" (值为dll文件的绝对路径) Xdebug.remote_enable=1 Xdebug.remote_host=127.0.0.1 Xdebug.remote_port=9000 Xdebug.idekey=phpstorm Xdebug.remote_autostart=1
注:第一行是加载Xdebug.romote_enable是开启远程调试,下面是远程调试的参数,ip、端口、识别字符串、自动远程调试。
c. 保存文件,重启apache。
d. 在CMD里输入 E:\php\php.exe -m 看到[Xend Modules]中出现如下字样Xdebug,说明开启成功。如下图
e. 至此,服务器端配置完毕。
注意:Xdebug就加载成功后,访问网站可能会会慢一些,原因是因为你开启了自动远程调试,每一次访问都会连接一下定义的ip和端口。
四、客户端配置:
1. 打开phpStorm,点击进入File>Settings>PHP>Servers。
2. 点击“+”,填写服务器端的相关信息,name填127.0.0.1,host填127.0.0.1,port填80,debugger选Xdebug,如下图:
3. 点击进入File>Settings>PHP>Debug。
4. 看到右侧Xdebug选项卡,Debug port填9000,其他默认
5. 点击进入File>Settings>PHP>Debug>DBGp Proxy
6. IDE key 填 phpStorm(与php.ini文件中的Xdebug.idekey值相同),host 填127.0.0.1,port 填80
7. 点OK退出设置。
8. 点击phpStorm界面右上角像电话一样的按钮,打开监听,如下图:
9. 如果变为绿色,则为开启监听成功,如下图:
五、开始调试
1. 打开php文件
2. 设置断点,如下图:
3. 点击run>debug,或者按Alt+Shift+F9,如下图:
4. 在弹出的对话框中选则带有php图标的php文件,如下图:
5. 底部会出现调试信息,如下图:
6. 按F8执行Step Over(单步进入函数),按F7执行Step Into(单步跳过函数),更多操作如下图:
7. 鼠标移至参数上之后,会出现当前的值,如下图:
8. 点击run>stop或者按Ctrl+F2,停止调试。