Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPStorm + XDebug + Vagrant

This question is about getting XDebug working in PHPStorm, when the project is running inside a local virtual machine which uses Vagrant. I haven't found any comprehensive manual how to get this running so far. Applies to PHPStorm 7.0.

The things I would like to have covered in the answer:

  • How should the XDebug configuration be set inside the VM? (xdebug.ini)
  • Is there a need to enable any additional ports in Vagrantfile?
  • How should the 'server' be set in PHPStorm?
  • How should the file mapping be set, when local files are synced with NFS into the Vagrant VM? Is there a need to set file mapping at all?
  • When tryng to 'validate remote environment', which of 'FTP', 'in place' or 'mounted folder' options should be picked?
  • Is it necessary to install an extension to the web browser?

I hope this might be useful as a definitive guide to get XDebug running with PHPStorm in Vagrant.

like image 649
Pavel S. Avatar asked Feb 12 '14 09:02

Pavel S.


1 Answers

How should the XDebug configuration be set inside the VM? (xdebug.ini)

This is my zzz_xdebug.ini file:

xdebug.remote_connect_back = 1
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.idekey = "PHPSTORM"

Is there a need to enable any additional ports in Vagrantfile?

Not as far as I know

How should the 'server' be set in PHPStorm?

Don't exactly know how I've configured this one. Just pointing it to mydomain.dev with debugger "Xdebug"

How should the file mapping be set, when local files are synced with NFS into the Vagrant VM? Is there a need to set file mapping at all?

When PHPStorm reaches for the very first time a breakpoint, it will ask for a mapping. Just select your local folder.

When tryng to 'validate remote environment', which of 'FTP', 'in place' or 'mounted folder' options should be picked?

How I've configured it, PHPStorm thinks it is all a local folder (in fact, it is). No FTP, mounted folder, shared drive etc. Just a local project.

Is it necessary to install an extension to the web browser?

Not an extension, but you can create a bookmarklet to start the xdebug session, see this page to create one.

Besides that, in your settings, you have to set Xebug setting "Can accept external connection" to true (check the box). To start listening for debug messages, you have to activate it in PHPStorm, see this image.

like image 99
trizz Avatar answered Nov 04 '22 10:11

trizz