Montag, 21. März 2016

Debugging PHP CLI scripts in PhpStorm which are running inside a Vagrant Box (Xdebug)

Please notice: This article is for debugging with Xdebug. Not any "old-fashioned" debugging with var_dump(); or print_r() or any other "90ies webmastering style".

Remote debugging by SSH tunnel and the PhpStorm debugger only

Additional settings in /etc/php5/cli/php.ini:

xdebug.remote_enable=true
xdebug.remote_autostart=true
xdebug.remote_port=9000
xdebug.remote_connect_back=1

Then connect to the server via SSH tunnel:

ssh -R 9000:localhost:9000 username_goes_here@hostname_goes_here 

Start a script via PHP from the command line and PhpStorm will react (debugging button in PhpStorm must be turned on and the mapping for the directories must be set).

This works, if you have not a weird issue with not available execution point inside PHPStorm's debugging window and there's no solution on the internet.. (Google isn't always your friend)

Remote debugging by the PhpStorm tools

In case that the debugger window will be opened, but the execution point will not be shown, you can run the script from PhpStorm itself.

Firstly you have to set up the remote debugging (Preferences > Languages & Framework > PHP). Choose here a remote interpreter.

If you have not already done so, set it up. The "SSH Credentials" settings have worked for me. While I'm using Vagrant and PhpStorm has an extra Vagrant checkbox (which has not worked for me):

In your PHP command line programs you need to specify often arguments. That can be done also:


Keine Kommentare:

Kommentar veröffentlichen