Xdebug is a PHP extension that provides us with debugging and profiling capabilities. It includes stack traces, real-time parameters' display, filenames, and line indicators. Sublime has a great plugin to help us debug our PHP code while using Xdebug. Having Xdebug installed is mandatory for this section; for more information, please visit: http://xdebug.org/docs/install.
There are two Xdebug plugins for Sublime. We will install the Xdebug Client. To install the SublimeTextXdebug
package, we'll use Package Control. Open the command palette by pressing Ctrl + Shift + P in Windows or Linux, and Command + Shift + P in OS X. Then choose Install Package and install the Xdebug Client package.
After installing, we'll need to change the xdebug.ini
configuration file:
[xdebug] zend_extension = "/absolute/path/to/our/xdebug-extension.so" ;zend_extension = "C:Program Files (x86)PHPextphp_xdebug.dll" Xdebug.remote_enable = 1 Xdebug.remote_host = "127.0.0.1" Xdebug.remote_port = 9000 Xdebug.remote_handler = "dbgp" Xdebug.remote_mode = req Xdebug.remote_connect_back = 1
If we are using a Linux/OS X platform, we should keep the Windows path commented and give an absolute path to our xdebug-extension.so
file. If we are using Windows, we should comment the first line by adding a semicolon, uncomment the second one by removing the semicolon, and change the path to where our php_xdebug.dll
file is located. We should restart the server after this.
The following screenshot is that of a debugging session:
As we can see in the preceding screenshot, all available Xdebug commands are being shown on the command palette, and we have three new windows at the bottom:
The following are all the commands that we will need to have for a good debugging session:
SublimeXdebug command |
Windows/Linux |
OS X |
---|---|---|
Start debugging |
Ctrl + Shift + F9 |
Command + Shift + F9 |
Stop debugging |
Ctrl + Shift + F10 |
Command + Shift + F10 |
Add/remove breakpoint |
Ctrl + F8 |
Command + F8 |
Set conditional breakpoint |
Shift + F8 |
Shift + F8 |
Run |
Ctrl + Shift + F5 |
Command + Shift + F5 |
Step over |
Ctrl + Shift + F6 |
Command + Shift + F6 |
Step into |
Ctrl + Shift + F7 |
Command + Shift + F7 |
Step out |
Ctrl + Shift + F8 |
Command + Shift + F8 |
All commands can also be found in the command palette by pressing Ctrl + Shift + P in Windows or Linux, and Command + Shift + P in OS X, or typing Xdebug:
in the Sublime Text menu under Tools | Xdebug.
If you are facing any trouble, try visiting the Troubleshoot page at: https://github.com/martomo/SublimeTextXdebug#troubleshoot.