Enable debugging in php


Below are great tutorials on how to enable php debugging with vim and xdebug:

  • https://mutelight.org/minimal-guide-to-debugging-php-with-xdebug-and-vim
  • http://www.weberp.org/forum/archive/index.php/thread-9.html

In a nutshell:

  1. sudo apt-get install vim php5-xdebug
  2. sudo vi /etc/php5/conf.d/xdebug.ini and append below content:

    Note: remove last line when in production, it’s pupose is to avoid having to run ?XDEBUG_SESSION_START=1 before debugging

  3. sudo apache2ctl restart
  4. download debugger.tar.gz from above link
  5. mkdir -p ~/.vim/plugin
  6. cd ~/.vim/plugin ; tar -xzf <path_to_debugger.tar.gz_file>

Vim usage

To learn how to use vim, open a shell and run ‘vimtutor’ to go through the tutorial!

Vim debugging tips

Once vim and xdebug are working together (simply run vim, hit F5 and refresh the page you want to analyze to start debugging – provided xdebug has been correctly configured to listen to port 9000), use the following commands:

  • use debug instructions displayed on right part of the screen
  • navigate to the line you are interested into and set ‘:Bp’ to add a breakpoint (green line)
  • go to the variable you are interested into and hit F12 to see its value/content
  • to investigate array values, go to ~/.vim/plugin/debugger.vim and edit line with content ‘let g:debuggerMaxDepth = 1’ and increase the value of this number, then restart vim

Xdebug debugging tips

  • to create permanent breakpoint, simply insert ‘xdebug_break();‘ into your php code and xdebug will automatically stop at this specific breakpoint



Post a Comment

Your email is never published nor shared. You're allow to say what you want...