Thursday, 6 October 2016

PhpStorm XDebug configuration when using VM (Vagrant)

I would like to take notes how I did my set up of PhpStorm IDE for debugging with XDebug with the server running on VM (Vagrant). I assume that this configuration will work also for other type of environments where you need to use remote debugging.

Server configuration

At first you have to install XDebug (out of scope of this article).

On the vagrant machine we need kind of this configuration in /etc/php.ini
[xdebug]
zend_extension=/home/www/PHP/php-5.5.22/lib/php/extensions/xdebug.so
xdebug.max_nesting_level=9999
xdebug.profiler_output_dir=/tmp/
xdebug.profiler_output_name=xdebug-%p
xdebug.profiler_append=1
xdebug.profiler_enable_trigger=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=10.0.25.21
;xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.idekey="PHPSTORM"
xdebug.remote_autostart=1
xdebug.profiler_enable=0
xdebug.trace_options=1

Restart apache or php processes (depending on your server setup).

Important settings are: remote_host, idekey, remote_enable, remote_autostart


Setup PhpStorm

Run -> Edit Configurations
+ (Add new configuration) -> PHP Remote Debug

  Name: My VM Debug Config
  Ide key (session id): PHPSTORM
  Servers: ... (add new) -> +

  Servers:
  Name: VM vagrant
  Port: 80
  Mappings: 
     File directory: /home/ptacnikt/work/main
     Absolute path on the server: /home/www/project_name

That should be it.





Debug

Then you can simply click the bug icon on the toolbar and then you can try to start unit tests or refresh you application in a browser and the focus get to the IDE with the Debug window opened.


Another settings

I also disabled the autostop on the first line, because I always setup a breakpoint by myself before starting the debugger.

File -> Settings -> Languages & Frameworks -> PHP -> Debug
  Uncheck both: "Force break at the first line .. "



No comments:

Post a Comment