Skip to content

Instantly share code, notes, and snippets.

@vuau
Last active August 16, 2021 14:26
Show Gist options
  • Save vuau/51c1b4d5c31b6f411e7a53bee61f85ac to your computer and use it in GitHub Desktop.
Save vuau/51c1b4d5c31b6f411e7a53bee61f85ac to your computer and use it in GitHub Desktop.
Debug PHP in Devilbox container with vdebug in vim

I use Devilbox to set up my development environment. Below is how I setup xdebug and debug PHP application in vim

Create configuration file, in host machine type these commands

cd [path_to_devilbox]/devilbox/cfg/php-ini-7.4
cp devilbox-php.ini-xdebug xdebug.ini

In xdebug.ini

[PHP]
xdebug.mode=debug
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.idekey=VSCODE
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.log=/var/log/php/xdebug.log

; The MacOS way
xdebug.remote_connect_back=0
xdebug.client_host=10.254.254.254

In .vimrc

  Plug 'vim-vdebug/vdebug'
  "vdebug
  let g:vdebug_options = {
      \   "port": 9003,
      \   "ide_key": "VSCODE",
      \   "path_maps": {"/shared/httpd": "/Users/aupham/Au/devilbox/data/www"}
      \}

To test xdebug configuration, I often create a file named debug.php like this

<?php xdebug_info(); ?>

More detail: https://xdebug.org/docs/all_functions#xdebug_info

Install xdebug browser extension: https://xdebug.org/docs/step_debug#browser-extensions

Restart docker

docker-compose rm -f && docker-compose up bind httpd php mysql redis

In Vim, open a PHP file and press F10 to set a breakpoint, F5 to start listening for xdebug server

To check if we are listening on the right port

lsof -P | grep 9003

Turn on Debug on the extension and reload the web page to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment