I recently came cross debugging in PHP. I know from my own experience that a lot of people are still using echo/print, var_dump to debug code. Nothing wrong but sometimes when you scratch you head wondering what’s inside that tiny variable, a proper debug tool can help you straight away.
There are a few big gun IDEs such as eclipse or NetBean, however for light weight tool, I configured NotePad++ with plugin DBGp. My environment is NotePad++ on Windows, connects to Apache+PHP on a Ubuntu Virtual Machine.
Below are some tips on configuration:
- Enable Samba on Ubuntu VM so that NotePad++ can access files on the Ubuntu VM.
- Install xdebug on php server site.
On Ubuntu, sudo apt-get php5-xdebug install
Configure /etc/php/apache2/php.ini with following lines
xdebug.remote_enable=1
xdebug.idekey=”XDEBUG_ECLIPSE”
xdebug.remote_host=192.168.1.104 (this is the Windows PC where NotePad++ runs)
xdebug.remote_port=9000
- Install NotePad++ and DBGp
DBGp configuration:
remote server IP: IP of Ubuntu VM
IDE KEY: XDEBUG_ECLIPSE, same as the above
Remote Path: file:///var/www/xxx/public/ where xxx is the site’s domain name. Note file:// with the extra /
Local Path: z:xxxpublic
- Install Xdebug helper(Chrome extension)
Then you’re ready to start debugging. In NotePad++, open any php file, set up a break point, enable “Debugger” (top in DBGp) menu then in Chrome, enable “Debug”(“Xdebug helper”), then type the URI in Chrome and you’ll notice NotePad++ blinks when means xdebug has intercepted the communication and starts working!