Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP debugging: How to configure Xdebug (for example, to use it for Vdebug -Vim plugin-)

How can I configure Xdebug so that it works for Vdebug -PHP debugger for Vim-?

I am trying to install Vdebug to debug PHP in Vim. Unfortunately, when I press F5 this message appears after a few seconds

Waiting for a connection (Ctrl-C to cancel, this message will self-destruct in
20  seconds...)
No connection was made

What should I do?

like image 599
pablofiumara Avatar asked Oct 02 '22 02:10

pablofiumara


2 Answers

I solved it and now Vdebug is working.

Enable xdebug in PHP Edit your php.ini file and add the following under the "Module Settings" section:

;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;

zend_extension=/path/to/my/xdebug.so

[debug]

; Remote settings

xdebug.remote_autostart=off

xdebug.remote_enable=on

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host=localhost

xdebug.remote_port=9000

; General xdebug.auto_trace=off

xdebug.collect_includes=on

xdebug.collect_params=off

xdebug.collect_return=off

xdebug.default_enable=on

xdebug.extended_info=1

xdebug.manual_url=http://www.php.net

xdebug.show_local_vars=0

xdebug.show_mem_delta=0

xdebug.max_nesting_level=100

;xdebug.idekey=

; Trace options

xdebug.trace_format=0

xdebug.trace_output_dir=/tmp

xdebug.trace_options=0

xdebug.trace_output_name=crc32

; Profiling

xdebug.profiler_append=0

xdebug.profiler_enable=0

xdebug.profiler_enable_trigger=0

xdebug.profiler_output_dir=/tmp

xdebug.profiler_output_name=crc32

Try it out

Everything should be ready to go now. Restart apache and run phpinfo() to see if any xdebug information comes up. If it doesn't, then the apache error_log + google are your friends.

Otherwise, you are ready to run the debugger inside vim.

Open a PHP script in VIM that you can access from your localhost Open that same PHP script in your web browser Add ?XDEBUG_SESSION_START=1 to the end of the URL In VIM, press F5. You should see at the bottom of VIM like "waiting for a new connection on port 9000 for 10 seconds..." Within the next 10 seconds, refresh the browser page with the "?XDEBUG_SESSION_START=1" on the end of the URL. Go back to VIM and you're in the debugger in all its glory. Don't forget: to switch between windows in VIM, press CTRL-w-w.

Source -it applies to Ubuntu though it refers to another linux distribution-

Hope this helps.

like image 134
pablofiumara Avatar answered Oct 10 '22 11:10

pablofiumara


I've also had this problem because i was using a different port for Xdebug.

In case of other port than 9000 set it on ~/.vimrc

let g:vdebug_options = {}
let g:vdebug_options["port"] = 9001
like image 44
Gui Avatar answered Oct 10 '22 10:10

Gui