It is very inefficient to debug PHP with the variable output by Echo,var_dump,print_r and so on. With Xdebug, you can debug PHP directly in the IDE.
Installing XdebugDownload Xdebug
Please download the corresponding PHP version of Xdebug
1 2 3 |
wget wget http: //xdebug .org /files/xdebug-2 .2.1.tgz tar xzvf xdebug-2.2.1.tgz cd xdebug-2.2.1 |
Installing XDEUBG
1 2 3 4 |
/usr/local/webserver/php/bin/phpize . /configure -- enable -xdebug --with-php-config= /usr/local/webserver/php/bin/php-config make cp modules /xdebug .so /usr/local/webserver/php/lib/php/extensions/ |
Modifications php.ini
, vi /usr/local/webserver/php/etc/php.ini
At the bottom, add the following:
1 2 3 4 5 6 7 8 |
[XDEBUG] zend_extension= "/usr/local/webserver/php/lib/php/extensions/xdebug.so" xdebug.remote_enable=on ; 此地址为IDE所在IP xdebug.remote_host=xxx.xxx.xxx.xxx xdebug.remote_port=9000 ; 可以是任意Key,这里设定为PHPSTORM xdebug.idekey= "PHPSTORM" |
Configure the IDE
I'm using the IDE is Phpstorm, so the following configurations are based on Phpstorm, others like Netbean and ECLIPCE
Inside the settings, select PHP---Debug, fill in the Xdebug just set the port, OK.
When set, click Run, start Listen PHP Debug Connections to turn on monitoring.
Configure the browser
The Firefox browser installs easy Xdebug and installs Xdebug helper on Chrome. After installation, IDE Key
fill in PHPSTORM
(need and configuration) can be.
Start Debug
After the setup is complete, add the appropriate breakpoint in the Phpstorm and then use the newly configured browser to access the page, and the first time you open Phpstorm will prompt to receive a connection from the server where PHP is located. For example, the debugger window already has debug information:
Debugging PHP code in Phpstorm